[Cbe-oss-dev] [PATCH 08/21] cell: catch errors from sysfs_create_group()

Michael Ellerman michael at ellerman.id.au
Wed Dec 5 20:52:25 EST 2007


On Wed, 2007-12-05 at 13:49 +1100, Jeremy Kerr wrote:
> We're currently getting a warning from not checking the result of
> sysfs_create_group, which is declared as __must_check.
> 
> This change introduces appropriate error-handling for
> spu_add_sysdev_attr_group()


I sent Greg a patch a while back to make sysfs_remove_group() safe to
call on non-added groups, which would make this a bit simpler:
http://lkml.org/lkml/2007/9/13/7

Still, list_for_each_entry_continue_reverse() is cool, I hope someone
implements list_for_each_entry_continue_safe_reverse_rcu() as well :)

cheers

> ---
>  arch/powerpc/platforms/cell/spu_base.c |   20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/cell/spu_base.c b/arch/powerpc/platforms/cell/spu_base.c
> index ee37e0e..f73263b 100644
> --- a/arch/powerpc/platforms/cell/spu_base.c
> +++ b/arch/powerpc/platforms/cell/spu_base.c
> @@ -574,13 +574,27 @@ EXPORT_SYMBOL_GPL(spu_add_sysdev_attr);
>  int spu_add_sysdev_attr_group(struct attribute_group *attrs)
>  {
>  	struct spu *spu;
> +	int rc = 0;
>  
>  	mutex_lock(&spu_full_list_mutex);
> -	list_for_each_entry(spu, &spu_full_list, full_list)
> -		sysfs_create_group(&spu->sysdev.kobj, attrs);
> +	list_for_each_entry(spu, &spu_full_list, full_list) {
> +		rc = sysfs_create_group(&spu->sysdev.kobj, attrs);
> +
> +		/* we're in trouble here, but try unwinding anyway */
> +		if (rc) {
> +			printk(KERN_ERR "%s: can't create sysfs group '%s'\n",
> +					__func__, attrs->name);
> +
> +			list_for_each_entry_continue_reverse(spu,
> +					&spu_full_list, full_list)
> +				sysfs_remove_group(&spu->sysdev.kobj, attrs);
> +			break;
> +		}
> +	}
> +
>  	mutex_unlock(&spu_full_list_mutex);
>  
> -	return 0;
> +	return rc;
>  }
>  EXPORT_SYMBOL_GPL(spu_add_sysdev_attr_group);
>  
> _______________________________________________
> cbe-oss-dev mailing list
> cbe-oss-dev at ozlabs.org
> https://ozlabs.org/mailman/listinfo/cbe-oss-dev
-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.ozlabs.org/pipermail/cbe-oss-dev/attachments/20071205/6aef3d6e/attachment.pgp>


More information about the cbe-oss-dev mailing list