drivers/block/aoe: handle sysfs errors
Subsystems (2)
PATCH 1/1 drivers/block/aoe: handle sysfs errors
Signed-off-by Jeff Garzik <[email protected]>
---
drivers/block/aoe/aoeblk.c | 64 +++++++++++++++++++++++++++++++++------------ 1 files changed, 47 insertions(+), 17 deletions(-)
drivers/block/aoe/aoeblk.c +47 -17
@@ -64,13 +64,36 @@ static struct disk_attribute disk_attr_f .show = aoedisk_show_fwver }; -static void +static int aoedisk_add_sysfs (struct aoedev *d) { -sysfs_create_file (&d->gd->kobj, &disk_attr_state.attr); -sysfs_create_file (&d->gd->kobj, &disk_attr_mac.attr); -sysfs_create_file (&d->gd->kobj, &disk_attr_netif.attr); -sysfs_create_file (&d->gd->kobj, &disk_attr_fwver.attr); +int err; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_state.attr); +if (err) +return err; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_mac.attr); +if (err) + goto err_out_state; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_netif.attr); +if (err) + goto err_out_mac; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_fwver.attr); +if (err) + goto err_out_netif; + +return 0 ; + +err_out_netif: +sysfs_remove_link (&d->gd->kobj,"netif" ); +err_out_mac: +sysfs_remove_link (&d->gd->kobj,"mac" ); +err_out_state: +sysfs_remove_link (&d->gd->kobj,"state" ); +return err; }void aoedisk_rm_sysfs (struct aoedev *d)
@@ -205,24 +228,18 @@ aoeblk_gdalloc(void *vp)if (gd ==NULL ) {printk (KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate disk " "structure for %ld.%ld\n" , d->aoemajor, d->aoeminor); -spin_lock_irqsave (&d->lock, flags); - d->flags &= ~DEVFL_GDALLOC ; -spin_unlock_irqrestore (&d->lock, flags); -return ; + goto err_out; } d->bufpool =mempool_create_slab_pool (MIN_BUFS , buf_pool_cache);if (d->bufpool ==NULL ) {printk (KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate bufpool " "for %ld.%ld\n" , d->aoemajor, d->aoeminor); -put_disk (gd); -spin_lock_irqsave (&d->lock, flags); - d->flags &= ~DEVFL_GDALLOC ; -spin_unlock_irqrestore (&d->lock, flags); -return ; + goto err_out_put; }spin_lock_irqsave (&d->lock, flags); +blk_queue_make_request (&d->blkq, aoeblk_make_request); gd->major =AOE_MAJOR ; gd->first_minor = d->sysminor *AOE_PARTITIONS ;
@@ -231,16 +248,29 @@ aoeblk_gdalloc(void *vp) gd->capacity = d->ssize;snprintf (gd->disk_name,sizeof gd->disk_name,"etherd/e%ld.%ld" , d->aoemajor, d->aoeminor); - gd->queue = &d->blkq; + +spin_unlock_irqrestore (&d->lock, flags); + +if (aoedisk_add_sysfs (d)) + goto err_out_put; + +spin_lock_irqsave (&d->lock, flags); d->gd = gd; d->flags &= ~DEVFL_GDALLOC ; d->flags |=DEVFL_UP ; -spin_unlock_irqrestore (&d->lock, flags);add_disk (gd); -aoedisk_add_sysfs (d); + +return ; + +err_out_put: +put_disk (gd); +err_out: +spin_lock_irqsave (&d->lock, flags); + d->flags &= ~DEVFL_GDALLOC ; +spin_unlock_irqrestore (&d->lock, flags); }void
Quoted 2 lines · Jeff Garzik
Signed-off-by Jeff Garzik <[email protected]>
Heh, I fixed this in my tree last night already :)
thanks though,
greg k-h
Quoted 31 lines · Jeff Garzik
Signed-off-by Jeff Garzik <[email protected]>---
drivers/block/aoe/aoeblk.c | 64 +++++++++++++++++++++++++++++++++------------ 1 files changed, 47 insertions(+), 17 deletions(-)drivers/block/aoe/aoeblk.c +8
-5@@ -64,13 +64,36 @@ static struct disk_attribute disk_attr_f .show = aoedisk_show_fwver }; -static void +static int aoedisk_add_sysfs (struct aoedev *d) { -sysfs_create_file (&d->gd->kobj, &disk_attr_state.attr); -sysfs_create_file (&d->gd->kobj, &disk_attr_mac.attr); -sysfs_create_file (&d->gd->kobj, &disk_attr_netif.attr); -sysfs_create_file (&d->gd->kobj, &disk_attr_fwver.attr); +int err; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_state.attr); +if (err) +return err; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_mac.attr);
drivers/block/aoe/aoeblk.c static struct disk_attribute disk_attr_f · line 86
Quoted 10 lines
drivers/block/aoe/aoeblk.c +10
-0+if (err) + goto err_out_state; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_netif.attr); +if (err) + goto err_out_mac; + + err =sysfs_create_file (&d->gd->kobj, &disk_attr_fwver.attr); +if (err) + goto err_out_netif;
Oh, and in the future, it's easier to use an attribute group for this kind of thing than backing out each and every attribute that is added. The function to add all files in the attribute group properly tears things down if there is an error along the way.
thanks,
greg k-h