scsi: core: fix error handling for dev_set_name
PATCH 1/1 scsi: core: fix error handling for dev_set_name
The driver do not handle the possible returning error of dev_set_name, if it returned fail, some operations should be rollback or there may be possible memory leak. We use put_device to free the device and use kfree to free the memory in the error handle path.
--- drivers/scsi/scsi_scan.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/scsi_scan.c +7 -1
@@ -509,7 +509,13 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,device_initialize (dev);kref_init (&starget->reap_ref); dev->parent =get_device (parent); -dev_set_name (dev,"target%d:%d:%d" , shost->host_no, channel, id); + error =dev_set_name (dev,"target%d:%d:%d" , shost->host_no, channel, id); +if (error) { +dev_err (dev,"%s: dev_set_name failed, error %d\n" , __func__, error); +put_device (dev); +kfree (starget); +return NULL ; + } dev->bus = &scsi_bus_type; dev->type = &scsi_target_type;scsi_enable_async_suspend (dev);
Signature · 1 line
2.17.1
Quoted 20 lines · Zhu Wang
The driver do not handle the possible returning error of
dev_set_name, if it returned fail, some operations should be rollback or there may be possible memory leak. We useput_deviceto free the device and use kfree to free the memory in the error handle path.Fixes 71610f55fa4d ("[SCSI] struct device - replace bus_id with dev_name(), dev_set_name()")Signed-off-by Zhu Wang <[email protected]>--- drivers/scsi/scsi_scan.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/scsi/scsi_scan.c +0
-1@@ -509,7 +509,13 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,device_initialize (dev);kref_init (&starget->reap_ref); dev->parent =get_device (parent); -dev_set_name (dev,"target%d:%d:%d" , shost->host_no, channel, id);
drivers/scsi/scsi_scan.c static struct scsi_target *scsi_alloc_target(struct device *parent, · line 521
Quoted 10 lines
drivers/scsi/scsi_scan.c +7
-0+ error =dev_set_name (dev,"target%d:%d:%d" , shost->host_no, channel, id); +if (error) { +dev_err (dev,"%s: dev_set_name failed, error %d\n" , __func__, error); +put_device (dev); +kfree (starget); +return NULL ; + } dev->bus = &scsi_bus_type; dev->type = &scsi_target_type;scsi_enable_async_suspend (dev);
I think that a put_device(parent) call is missing from the error path.
Thanks,
Bart.