Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp657802imm; Wed, 8 Aug 2018 03:33:44 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxuAuKLUZvdbyiQewzytZ5Wq75P7D8BtDYJ5M0UDj34GdYAKEVxLb07uuD0jDaS+3vn5Btz X-Received: by 2002:a65:538e:: with SMTP id x14-v6mr1998810pgq.388.1533724424459; Wed, 08 Aug 2018 03:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533724424; cv=none; d=google.com; s=arc-20160816; b=rWdSOR5dhDJ+RlSgTCgXzGVbpUbf7cyHpAK5RLfIT6tjOUuA/O9NACncIIiayIbB2b rbu3+76hNl0PCl/jNBF2i1fVexfwZ8hBpDjNprEIGGv4WOyELjTAbscwUDo2SP3cYWAJ OIMowtCqQd2dvwBCfXmgp5xQ/k+hYXwgniqW/csnWOizvFf/LStFWoOcoynpPauV8eis uFs7VeGcf1IMoluG98KvfwMBNhAZZTM1xtZi3k2UQr7+Pv75eGX6FTMoZK5PDsV84jR0 AyptM19ZUJlwBYdVgxXkQDHxIjkKN1OCYC3qPaQjwep+01YlE7r08AH1Zp7R8+1v061U zTgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:arc-authentication-results; bh=KaUztAhBoR7CTirfceghR0MP8Oi8cv7WKLL5No34+f0=; b=Bx2SykNTiBNqOP65HUNiAzAQneozmHuANTXGpLyYTqswScsAwUAEcx0D/2wDj8xu6G AYVjhFFGv8nG3FwnwXmrt/d6PYBYoKY1Nhghg5tclwGCogYBRxNgQwZ36lIB8vIgqA8z 4eCuJPKNY1whOTxTDAUft3JB+YKfbY5Cqc72TWoxoU8HqUmaELKI4Ih4exyZ6qMwtSaH LNoSfnNla+TaMXaUiblPn+FMzh/ShAphxR6WzpXYR0V3I734P0hrRrD1A7hkRxSxIZIr 03jg6eeGZC6a26Kni/a1PW+QOuFqub6Y886d6w7yeHSZH4hBR6NefS0mIIqA5c2elZCM 2gCQ== ARC-Authentication-Results: i=1; mx.google.com; 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 n10-v6si4235514pfb.316.2018.08.08.03.33.29; Wed, 08 Aug 2018 03:33:44 -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; 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 S1726954AbeHHMvq (ORCPT + 99 others); Wed, 8 Aug 2018 08:51:46 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:60008 "EHLO slow1-d.mail.gandi.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726745AbeHHMvq (ORCPT ); Wed, 8 Aug 2018 08:51:46 -0400 Received: from relay9-d.mail.gandi.net (unknown [217.70.183.199]) by slow1-d.mail.gandi.net (Postfix) with ESMTP id 701DD3A6FBA; Wed, 8 Aug 2018 12:27:28 +0200 (CEST) X-Originating-IP: 209.85.216.171 Received: from mail-qt0-f171.google.com (mail-qt0-f171.google.com [209.85.216.171]) (Authenticated sender: aditya@kobol.io) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 53104FF80A; Wed, 8 Aug 2018 10:27:26 +0000 (UTC) Received: by mail-qt0-f171.google.com with SMTP id n6-v6so1769443qtl.4; Wed, 08 Aug 2018 03:27:26 -0700 (PDT) X-Gm-Message-State: AOUpUlGbX0yXbh0MIQhojSj/9rOrqaGlfeVuD/QGHO7gyZHQqmv29dR1 C+uPiLwvutE8mXDirrK4QqJ4f6bp5qfvKBOu814= X-Received: by 2002:a0c:9692:: with SMTP id a18-v6mr1873869qvd.16.1533724045196; Wed, 08 Aug 2018 03:27:25 -0700 (PDT) MIME-Version: 1.0 References: <1533522556-55055-1-git-send-email-aditya@kobol.io> <1533522556-55055-2-git-send-email-aditya@kobol.io> <20180806033802.GA32450@lunn.ch> In-Reply-To: <20180806033802.GA32450@lunn.ch> From: Aditya Prayoga Date: Wed, 8 Aug 2018 17:27:16 +0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH RESEND 1/2] gpio: mvebu: Add support for multiple PWM lines per GPIO chip To: andrew@lunn.ch Cc: linux-gpio@vger.kernel.org, richard.genoud@gmail.com, gregory.clement@bootlin.com, Gauthier Provost , alban.browaeys@gmail.com, thierry.reding@gmail.com, linus.walleij@linaro.org, linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Gilmore , ralph.sennhauser@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 6, 2018 at 10:38 AM Andrew Lunn wrote: > > 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 Hi Andrew, Thanks, I will fix it on next version. Regards, Aditya