Skip to content

Commit a24484f

Browse files
fujitaJames Bottomley
authored andcommitted
[SCSI] sg: set class_data after success
If cdev_add fails in sg_add, sg_remove crashes since class_data is bogus. Signed-off-by: FUJITA Tomonori <[email protected]> Acked-by: Douglas Gilbert <[email protected]> Signed-off-by: James Bottomley <[email protected]>
1 parent d814c51 commit a24484f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/scsi/sg.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,6 @@ sg_add(struct class_device *cl_dev, struct class_interface *cl_intf)
14221422
goto out;
14231423
}
14241424

1425-
class_set_devdata(cl_dev, sdp);
14261425
error = cdev_add(cdev, MKDEV(SCSI_GENERIC_MAJOR, sdp->index), 1);
14271426
if (error)
14281427
goto cdev_add_err;
@@ -1451,6 +1450,8 @@ sg_add(struct class_device *cl_dev, struct class_interface *cl_intf)
14511450
"Attached scsi generic sg%d type %d\n", sdp->index,
14521451
scsidp->type);
14531452

1453+
class_set_devdata(cl_dev, sdp);
1454+
14541455
return 0;
14551456

14561457
cdev_add_err:

0 commit comments

Comments
 (0)