mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Aditya Prayoga <aditya@kobol.io>
Cc: linux-gpio@vger.kernel.org,
	Richard Genoud <richard.genoud@gmail.com>,
	Gregory CLEMENT <gregory.clement@bootlin.com>,
	Gauthier Provost <gauthier@kobol.io>,
	Alban Browaeys <alban.browaeys@gmail.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Dennis Gilmore <dennis@ausil.us>,
	Ralph Sennhauser <ralph.sennhauser@gmail.com>
Subject: Re: [PATCH RESEND 1/2] gpio: mvebu: Add support for multiple PWM lines per GPIO chip
Date: Mon, 6 Aug 2018 05:38:02 +0200	[thread overview]
Message-ID: <20180806033802.GA32450@lunn.ch> (raw)
In-Reply-To: <1533522556-55055-2-git-send-email-aditya@kobol.io>

On Mon, Aug 06, 2018 at 10:29:15AM +0800, Aditya Prayoga wrote:

Hi Aditya

> +	item = kzalloc(sizeof(*item), GFP_KERNEL);
> +	if (!item)
> +		return -ENODEV;

ENOMEM would be better, since it is a memory allocation which is
failing.

>  
> -		ret = gpiod_direction_output(desc, 0);
> -		if (ret) {
> -			gpiochip_free_own_desc(desc);
> -			goto out;
> -		}
> +	spin_lock_irqsave(&mvpwm->lock, flags);
> +	desc = gpiochip_request_own_desc(&mvchip->chip,
> +					 pwm->hwpwm, "mvebu-pwm");
> +	if (IS_ERR(desc)) {
> +		ret = PTR_ERR(desc);
> +		goto out;
> +	}
>  
> -		mvpwm->gpiod = desc;
> +	ret = gpiod_direction_output(desc, 0);
> +	if (ret) {
> +		gpiochip_free_own_desc(desc);
> +		goto out;
>  	}
> +	item->gpiod = desc;
> +	item->device = pwm;
> +	INIT_LIST_HEAD(&item->node);
> +	list_add_tail(&item->node, &mvpwm->pwms);
>  out:
>  	spin_unlock_irqrestore(&mvpwm->lock, flags);
>  	return ret;

You don't cleanup item on the error path.

> @@ -630,12 +639,20 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
>  static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
>  {
>  	struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
> +	struct mvebu_pwm_item *item, *tmp;
>  	unsigned long flags;
>  
> -	spin_lock_irqsave(&mvpwm->lock, flags);
> -	gpiochip_free_own_desc(mvpwm->gpiod);
> -	mvpwm->gpiod = NULL;
> -	spin_unlock_irqrestore(&mvpwm->lock, flags);
> +	list_for_each_entry_safe(item, tmp, &mvpwm->pwms, node) {
> +		if (item->device == pwm) {
> +			spin_lock_irqsave(&mvpwm->lock, flags);
> +			gpiochip_free_own_desc(item->gpiod);
> +			item->gpiod = NULL;
> +			item->device = NULL;

Since you are about to free item, these two lines are pointless.

> +			list_del(&item->node);
> +			spin_unlock_irqrestore(&mvpwm->lock, flags);
> +			kfree(item);
> +		}
> +	}
>  }

   Andrew

  reply	other threads:[~2018-08-06  3:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-06  2:29 [PATCH RESEND 0/2] gpio: mvebu: Add support for multiple PWM lines Aditya Prayoga
2018-08-06  2:29 ` [PATCH RESEND 1/2] gpio: mvebu: Add support for multiple PWM lines per GPIO chip Aditya Prayoga
2018-08-06  3:38   ` Andrew Lunn [this message]
2018-08-08 10:27     ` Aditya Prayoga
2018-08-29  7:54   ` Linus Walleij
2018-08-29  8:02     ` Thomas Petazzoni
2018-08-29 12:09       ` Linus Walleij
2018-08-29 12:52         ` Andrew Lunn
2018-08-29  8:13     ` Gregory CLEMENT
2018-08-06  2:29 ` [PATCH RESEND 2/2] gpio: mvebu: Allow to use non-default PWM counter Aditya Prayoga
2018-08-06 13:52   ` Andrew Lunn
2018-08-08 11:40     ` Aditya Prayoga
2018-08-09 15:03     ` Richard Genoud
2018-08-09 15:43       ` Andrew Lunn

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=20180806033802.GA32450@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=aditya@kobol.io \
    --cc=alban.browaeys@gmail.com \
    --cc=dennis@ausil.us \
    --cc=gauthier@kobol.io \
    --cc=gregory.clement@bootlin.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=ralph.sennhauser@gmail.com \
    --cc=richard.genoud@gmail.com \
    --cc=thierry.reding@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome