Skip to content

Commit 26cd4d6

Browse files
xtfengJeff Garzik
authored and
Jeff Garzik
committed
[libata] fix Null pointer dereference on disk error
Following oops were observed when disk error happened: [ 4272.896937] sd 0:0:0:0: [sda] Unhandled error code [ 4272.896939] sd 0:0:0:0: [sda] Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK [ 4272.896942] sd 0:0:0:0: [sda] CDB: Read(10): 28 00 00 5a de a7 00 00 08 00 [ 4272.896951] end_request: I/O error, dev sda, sector 5955239 [ 4291.574947] BUG: unable to handle kernel NULL pointer dereference at (null) [ 4291.658305] IP: [] ahci_activity_show+0x1/0x40 [ 4291.730090] PGD 76dbbc067 PUD 6c4fba067 PMD 0 [ 4291.783408] Oops: 0000 [#1] SMP [ 4291.822100] last sysfs file: /sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/sw_activity [ 4291.934235] CPU 9 [ 4291.958301] Pid: 27942, comm: hwinfo ...... ata_scsi_find_dev could return NULL, so ata_scsi_activity_{show,store} should check if atadev is NULL. Signed-off-by: Xiaotian Feng <[email protected]> Cc: James Bottomley <[email protected]> Cc: [email protected] Signed-off-by: Jeff Garzik <[email protected]>
1 parent 39f80ac commit 26cd4d6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/ata/libata-scsi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ ata_scsi_activity_show(struct device *dev, struct device_attribute *attr,
309309
struct ata_port *ap = ata_shost_to_port(sdev->host);
310310
struct ata_device *atadev = ata_scsi_find_dev(ap, sdev);
311311

312-
if (ap->ops->sw_activity_show && (ap->flags & ATA_FLAG_SW_ACTIVITY))
312+
if (atadev && ap->ops->sw_activity_show &&
313+
(ap->flags & ATA_FLAG_SW_ACTIVITY))
313314
return ap->ops->sw_activity_show(atadev, buf);
314315
return -EINVAL;
315316
}
@@ -324,7 +325,8 @@ ata_scsi_activity_store(struct device *dev, struct device_attribute *attr,
324325
enum sw_activity val;
325326
int rc;
326327

327-
if (ap->ops->sw_activity_store && (ap->flags & ATA_FLAG_SW_ACTIVITY)) {
328+
if (atadev && ap->ops->sw_activity_store &&
329+
(ap->flags & ATA_FLAG_SW_ACTIVITY)) {
328330
val = simple_strtoul(buf, NULL, 0);
329331
switch (val) {
330332
case OFF: case BLINK_ON: case BLINK_OFF:

0 commit comments

Comments
 (0)