All of lore.kernel.org
 help / color / mirror / Atom feed
From: thierry.reding@avionic-design.de (Thierry Reding)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] pwm-core: fix registration of several pwm
Date: Sun, 29 Apr 2012 19:14:18 +0200	[thread overview]
Message-ID: <20120429171418.GC29827@avionic-0098.adnet.avionic-design.de> (raw)
In-Reply-To: <1335713330-6488-3-git-send-email-eric@eukrea.com>

* Eric B?nard wrote:
> * after a pwm is allocated using alloc_pwms, ret contains the number
> of the pwm and is returned by pwmchip_add so the calling driver
> (pwm-imx in my case) fails with the following log :
> mxc_pwm: probe of mxc_pwm.1 failed with error 1
> mxc_pwm: probe of mxc_pwm.2 failed with error 2
> mxc_pwm: probe of mxc_pwm.3 failed with error 3
> 
> * this patch fix error handling in pwmchip_add
> 
> Signed-off-by: Eric B?nard <eric@eukrea.com>
> ---
>  drivers/pwm/core.c |    7 +++++--
>  1 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index a7be0bc..d3438e4 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -216,8 +216,10 @@ int pwmchip_add(struct pwm_chip *chip)
>  		goto out;
>  
>  	chip->pwms = kzalloc(chip->npwm * sizeof(*pwm), GFP_KERNEL);
> -	if (!chip->pwms)
> -		return -ENOMEM;
> +	if (!chip->pwms) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}

Good catch!

>  
>  	chip->base = ret;
>  
> @@ -239,6 +241,7 @@ int pwmchip_add(struct pwm_chip *chip)
>  	if (IS_ENABLED(CONFIG_OF))
>  		of_pwmchip_add(chip);
>  
> +	ret = 0;
>  out:
>  	mutex_unlock(&pwm_lock);
>  	return ret;

pwmchip_add() is meant to return a negative error-code on failure, so a
positive return values would still indicate success, therefore any callers
should check explicitly for (ret < 0) instead of just (ret). However in this
case it might be safer to make the return value explicitly 0 in case of
success.

I'd like to fold this into the existing series as well, if that's okay with
you.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120429/9288c84e/attachment.sig>

  reply	other threads:[~2012-04-29 17:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-29 15:28 [PATCH 1/3] pwm-core: fix compilation when OF is not selected Eric Bénard
2012-04-29 15:28 ` [PATCH 2/3] pwm-imx: set chip.dev to prevent probe failure Eric Bénard
2012-04-29 17:07   ` Thierry Reding
2012-04-29 15:28 ` [PATCH 3/3] pwm-core: fix registration of several pwm Eric Bénard
2012-04-29 17:14   ` Thierry Reding [this message]
2012-04-29 17:04 ` [PATCH 1/3] pwm-core: fix compilation when OF is not selected Thierry Reding
2012-04-29 17:32   ` Eric Bénard
2012-04-29 18:59   ` Eric Bénard
2012-04-29 19:04     ` Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120429171418.GC29827@avionic-0098.adnet.avionic-design.de \
    --to=thierry.reding@avionic-design.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.