Skip to content

Commit 9b6d90e

Browse files
zhou1615Damien Le Moal
authored andcommitted
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: f3d5e4f ("ata: pata_of_platform: Allow to use 16-bit wide data transfer") Signed-off-by: Zhou Qingyang <[email protected]> Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Sergey Shtylyov <[email protected]>
1 parent 0280e3c commit 9b6d90e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/ata/pata_platform.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ int __pata_platform_probe(struct device *dev, struct resource *io_res,
128128
ap = host->ports[0];
129129

130130
ap->ops = devm_kzalloc(dev, sizeof(*ap->ops), GFP_KERNEL);
131+
if (!ap->ops)
132+
return -ENOMEM;
131133
ap->ops->inherits = &ata_sff_port_ops;
132134
ap->ops->cable_detect = ata_cable_unknown;
133135
ap->ops->set_mode = pata_platform_set_mode;

0 commit comments

Comments
 (0)