Skip to content

Commit 0293902

Browse files
Wang Chentorvalds
authored andcommitted
I2O: handle sysfs_create_link() failures
Compile warning: ignoring return value of `sysfs_create_link', declared with attribute warn_unused_result. If sysfs_create_link failed, take care of the return value and do some error handle after the failure. Since sysfs_remove_link() will check whether a link exists, when removing the link in error path, we don't need to care whether a link was created. Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com> Cc: Markus Lidel <Markus.Lidel@shadowconnect.com> Cc: Jens Axboe <jens.axboe@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f700d6e commit 0293902

1 file changed

Lines changed: 42 additions & 12 deletions

File tree

‎drivers/message/i2o/device.c‎

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,36 +243,66 @@ static int i2o_device_add(struct i2o_controller *c, i2o_lct_entry *entry)
243243

244244
/* create user entries for this device */
245245
tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.user_tid);
246-
if (tmp && (tmp != i2o_dev))
247-
sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj,
248-
"user");
246+
if (tmp && (tmp != i2o_dev)) {
247+
rc = sysfs_create_link(&i2o_dev->device.kobj,
248+
&tmp->device.kobj, "user");
249+
if (rc)
250+
goto unreg_dev;
251+
}
249252

250253
/* create user entries refering to this device */
251254
list_for_each_entry(tmp, &c->devices, list)
252255
if ((tmp->lct_data.user_tid == i2o_dev->lct_data.tid)
253-
&& (tmp != i2o_dev))
254-
sysfs_create_link(&tmp->device.kobj,
255-
&i2o_dev->device.kobj, "user");
256+
&& (tmp != i2o_dev)) {
257+
rc = sysfs_create_link(&tmp->device.kobj,
258+
&i2o_dev->device.kobj, "user");
259+
if (rc)
260+
goto rmlink1;
261+
}
256262

257263
/* create parent entries for this device */
258264
tmp = i2o_iop_find_device(i2o_dev->iop, i2o_dev->lct_data.parent_tid);
259-
if (tmp && (tmp != i2o_dev))
260-
sysfs_create_link(&i2o_dev->device.kobj, &tmp->device.kobj,
261-
"parent");
265+
if (tmp && (tmp != i2o_dev)) {
266+
rc = sysfs_create_link(&i2o_dev->device.kobj,
267+
&tmp->device.kobj, "parent");
268+
if (rc)
269+
goto rmlink1;
270+
}
262271

263272
/* create parent entries refering to this device */
264273
list_for_each_entry(tmp, &c->devices, list)
265274
if ((tmp->lct_data.parent_tid == i2o_dev->lct_data.tid)
266-
&& (tmp != i2o_dev))
267-
sysfs_create_link(&tmp->device.kobj,
268-
&i2o_dev->device.kobj, "parent");
275+
&& (tmp != i2o_dev)) {
276+
rc = sysfs_create_link(&tmp->device.kobj,
277+
&i2o_dev->device.kobj, "parent");
278+
if (rc)
279+
goto rmlink2;
280+
}
269281

270282
i2o_driver_notify_device_add_all(i2o_dev);
271283

272284
pr_debug("i2o: device %s added\n", i2o_dev->device.bus_id);
273285

274286
return 0;
275287

288+
rmlink2:
289+
/* If link creating failed halfway, we loop whole list to cleanup.
290+
* And we don't care wrong removing of link, because sysfs_remove_link
291+
* will take care of it.
292+
*/
293+
list_for_each_entry(tmp, &c->devices, list) {
294+
if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid)
295+
sysfs_remove_link(&tmp->device.kobj, "parent");
296+
}
297+
sysfs_remove_link(&i2o_dev->device.kobj, "parent");
298+
rmlink1:
299+
list_for_each_entry(tmp, &c->devices, list)
300+
if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid)
301+
sysfs_remove_link(&tmp->device.kobj, "user");
302+
sysfs_remove_link(&i2o_dev->device.kobj, "user");
303+
unreg_dev:
304+
list_del(&i2o_dev->list);
305+
device_unregister(&i2o_dev->device);
276306
err:
277307
kfree(i2o_dev);
278308
return rc;

0 commit comments

Comments
 (0)