From a24484f281dda11e4fc0041a51907d3564da3d7f Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Tue, 15 Jan 2008 13:17:47 +0900 Subject: [PATCH] [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 Acked-by: Douglas Gilbert Signed-off-by: James Bottomley --- drivers/scsi/sg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index e65f5d4326..ebbf9b4b7e 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1422,7 +1422,6 @@ sg_add(struct class_device *cl_dev, struct class_interface *cl_intf) goto out; } - class_set_devdata(cl_dev, sdp); error = cdev_add(cdev, MKDEV(SCSI_GENERIC_MAJOR, sdp->index), 1); if (error) goto cdev_add_err; @@ -1451,6 +1450,8 @@ sg_add(struct class_device *cl_dev, struct class_interface *cl_intf) "Attached scsi generic sg%d type %d\n", sdp->index, scsidp->type); + class_set_devdata(cl_dev, sdp); + return 0; cdev_add_err: -- 2.39.5