Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: pata_platform: Fix a NULL pointer dereference in __pata_platform_probe()

In __pata_platform_probe(), devm_kzalloc() is assigned to ap->ops and
there is a dereference of it right after that, which could introduce a
NULL pointer dereference bug.

Fix this by adding a NULL check of ap->ops.

This bug was found by a static analyzer.

Builds with 'make allyesconfig' show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: f3d5e4f18dba ("ata: pata_of_platform: Allow to use 16-bit wide data transfer")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

authored by

Zhou Qingyang and committed by
Damien Le Moal
9b6d90e2 0280e3c5

+2
+2
drivers/ata/pata_platform.c
··· 128 128 ap = host->ports[0]; 129 129 130 130 ap->ops = devm_kzalloc(dev, sizeof(*ap->ops), GFP_KERNEL); 131 + if (!ap->ops) 132 + return -ENOMEM; 131 133 ap->ops->inherits = &ata_sff_port_ops; 132 134 ap->ops->cable_detect = ata_cable_unknown; 133 135 ap->ops->set_mode = pata_platform_set_mode;