Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3082698imm; Sun, 5 Aug 2018 20:40:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcRrb7bjV0esNLxXqTMT4T8vVQG3ACw60Hb0nrF7kq+JU2uwPzzWLlmlr1cp5RibSixPHxu X-Received: by 2002:a17:902:bc8b:: with SMTP id bb11-v6mr12167873plb.112.1533526843716; Sun, 05 Aug 2018 20:40:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533526843; cv=none; d=google.com; s=arc-20160816; b=M62HLxRHZSruuPp1DVlXsCtlUXtMKGnEqaQg8X5PfldU3mDO7YP+C1Zxup/cia8OP2 sHKWNGYmUmfUzxMhJFe7ZBblgIvHkEj0nATFBFRZpWuW0BqYxA2xRrB9BlWIUyyEZngi uKaqrnKoNWfvQo1bCArKq1jrwLfESTEsy4C25p2bZY0c9sEku+e+nuCjw7g/OmLce0V4 Xy1ojWs79bWfi83MNYA8co3+kvXfd3WcnWIYeCqKMWhdVCGrPMlKfTPpGrpxbCvNRcL4 cIAZfKyW7k6sFcZFb9FUaaBDMNEl5frlPiLenTJw11ZSRSOtzNIplsj0j02CPv97gwLq xkZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=qPsd2eaJs7rzfqFdyYsjDqlyo1TFKdf7sAWS4BBbSvE=; b=oBf4a15Y23YLbEowB6x96f4kQM4lyKbk7plraUO3KIIbPiK+Ue7RVPOhWaddq3kJaf 8FlvvTAAspv/SodCyUWoD5qC44WjdZrsA9Vr/ZywWwGWRyeGIQYsDmJyz69DZP6wacXv HNSTZchze8Ixo3XGscMNDeuyszWYLYvFbSJi36mTrkd1ymuC/Ifuu6TaC6TbcqxXNGNI Wr+uW5BZu4Yr//9YzhTLyRm+rgZi837AgwIFweN4nDckWCXKwXNI0VLM6Ub584UABid6 YfQOvpacdNx1EptqNesQ5CxAwtwfKEhkrSbeffqQS7/Cy8/HKhRyAHm7xya506npADdy 33nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=y9YzBAQc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q65-v6si12340403pfb.9.2018.08.05.20.40.06; Sun, 05 Aug 2018 20:40:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=y9YzBAQc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727580AbeHFFpM (ORCPT + 99 others); Mon, 6 Aug 2018 01:45:12 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:55986 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726559AbeHFFpL (ORCPT ); Mon, 6 Aug 2018 01:45:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=qPsd2eaJs7rzfqFdyYsjDqlyo1TFKdf7sAWS4BBbSvE=; b=y9YzBAQcjd5SyOxDRUlbLdY7QHKQ50hp7Jw61CEnXiSHTiq+4tRpwERrT1OnFyfnzimPFh8Cc1RWBoNbIQKkubRgduMDG0OQUHrYULuWFtNrPx3RRQOFm7xjp/tItHpeGZ1yOf/afHBPO18cKPuAg5861YMdzjoIAKg1SdSjwaE=; Received: from andrew by vps0.lunn.ch with local (Exim 4.84_2) (envelope-from ) id 1fmWLK-0008UQ-J6; Mon, 06 Aug 2018 05:38:02 +0200 Date: Mon, 6 Aug 2018 05:38:02 +0200 From: Andrew Lunn To: Aditya Prayoga Cc: linux-gpio@vger.kernel.org, Richard Genoud , Gregory CLEMENT , Gauthier Provost , Alban Browaeys , Thierry Reding , Linus Walleij , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Gilmore , Ralph Sennhauser Subject: Re: [PATCH RESEND 1/2] gpio: mvebu: Add support for multiple PWM lines per GPIO chip Message-ID: <20180806033802.GA32450@lunn.ch> References: <1533522556-55055-1-git-send-email-aditya@kobol.io> <1533522556-55055-2-git-send-email-aditya@kobol.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1533522556-55055-2-git-send-email-aditya@kobol.io> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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