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

libata: add missing NULL pointer check to ata_eh_reset()

drivers/ata/libata-eh.c +2403 ata_eh_reset(80) warning: variable derefenced before check 'slave'

Please note that this is _not_ a real bug at the moment since ata_eh_context
structure is embedded into ata_list structure and the code alwas checks for
'slave' before accessing 'sehc'.

Anyway lets add missing check and always have a valid 'sehc' pointer (which
makes code easier to understand and prevents introducing some possible bugs
in the future).

Reported-by: Dan Carpenter <error27@gmail.com>
Cc: corbet@lwn.net
Cc: eteo@redhat.com
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>

authored by

Bartlomiej Zolnierkiewicz and committed by
Jeff Garzik
705d2014 044dcc82

+1 -1
+1 -1
drivers/ata/libata-eh.c
··· 2327 2327 struct ata_port *ap = link->ap; 2328 2328 struct ata_link *slave = ap->slave_link; 2329 2329 struct ata_eh_context *ehc = &link->eh_context; 2330 - struct ata_eh_context *sehc = &slave->eh_context; 2330 + struct ata_eh_context *sehc = slave ? &slave->eh_context : NULL; 2331 2331 unsigned int *classes = ehc->classes; 2332 2332 unsigned int lflags = link->flags; 2333 2333 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);