Skip to content

Commit 3889b26

Browse files
Jeff GarzikLinus Torvalds
authored andcommitted
[PATCH] I2O: more error checking
i2o_scsi: handle sysfs failure i2o_device: * convert i2o_device_add() to return integer error code rather than pointer. Fortunately -nobody- checks the return code of this function, so changing has nil impact. * handle errors thrown by device_register() More work in i2o_device remains. Signed-off-by: Jeff Garzik <jeff@garzik.org> Cc: Markus Lidel <Markus.Lidel@shadowconnect.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 07354a0 commit 3889b26

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

‎drivers/message/i2o/device.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,17 @@ static struct i2o_device *i2o_device_alloc(void)
214214
* Allocate a new I2O device and initialize it with the LCT entry. The
215215
* device is appended to the device list of the controller.
216216
*
217-
* Returns a pointer to the I2O device on success or negative error code
218-
* on failure.
217+
* Returns zero on success, or a -ve errno.
219218
*/
220-
static struct i2o_device *i2o_device_add(struct i2o_controller *c,
221-
i2o_lct_entry * entry)
219+
static int i2o_device_add(struct i2o_controller *c, i2o_lct_entry *entry)
222220
{
223221
struct i2o_device *i2o_dev, *tmp;
222+
int rc;
224223

225224
i2o_dev = i2o_device_alloc();
226225
if (IS_ERR(i2o_dev)) {
227226
printk(KERN_ERR "i2o: unable to allocate i2o device\n");
228-
return i2o_dev;
227+
return PTR_ERR(i2o_dev);
229228
}
230229

231230
i2o_dev->lct_data = *entry;
@@ -236,7 +235,9 @@ static struct i2o_device *i2o_device_add(struct i2o_controller *c,
236235
i2o_dev->iop = c;
237236
i2o_dev->device.parent = &c->device;
238237

239-
device_register(&i2o_dev->device);
238+
rc = device_register(&i2o_dev->device);
239+
if (rc)
240+
goto err;
240241

241242
list_add_tail(&i2o_dev->list, &c->devices);
242243

@@ -270,7 +271,11 @@ static struct i2o_device *i2o_device_add(struct i2o_controller *c,
270271

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

273-
return i2o_dev;
274+
return 0;
275+
276+
err:
277+
kfree(i2o_dev);
278+
return rc;
274279
}
275280

276281
/**

‎drivers/message/i2o/i2o_scsi.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static int i2o_scsi_probe(struct device *dev)
220220
u32 id = -1;
221221
u64 lun = -1;
222222
int channel = -1;
223-
int i;
223+
int i, rc;
224224

225225
i2o_shost = i2o_scsi_get_host(c);
226226
if (!i2o_shost)
@@ -304,14 +304,20 @@ static int i2o_scsi_probe(struct device *dev)
304304
return PTR_ERR(scsi_dev);
305305
}
306306

307-
sysfs_create_link(&i2o_dev->device.kobj, &scsi_dev->sdev_gendev.kobj,
308-
"scsi");
307+
rc = sysfs_create_link(&i2o_dev->device.kobj,
308+
&scsi_dev->sdev_gendev.kobj, "scsi");
309+
if (rc)
310+
goto err;
309311

310312
osm_info("device added (TID: %03x) channel: %d, id: %d, lun: %ld\n",
311313
i2o_dev->lct_data.tid, channel, le32_to_cpu(id),
312314
(long unsigned int)le64_to_cpu(lun));
313315

314316
return 0;
317+
318+
err:
319+
scsi_remove_device(scsi_dev);
320+
return rc;
315321
};
316322

317323
static const char *i2o_scsi_info(struct Scsi_Host *SChost)

0 commit comments

Comments
 (0)