Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933331AbbELNAT (ORCPT ); Tue, 12 May 2015 09:00:19 -0400 Received: from metis.ext.pengutronix.de ([92.198.50.35]:55212 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932964AbbELNAO (ORCPT ); Tue, 12 May 2015 09:00:14 -0400 Date: Tue, 12 May 2015 15:00:05 +0200 From: Sascha Hauer To: YH Huang Cc: Matthias Brugger , Mark Rutland , Thierry Reding , Rob Herring , Pawel Moll , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, srv_heupstream@mediatek.com, linux-mediatek@lists.infradead.org, Sascha Hauer Subject: Re: [PATCH 2/2] pwm: add Mediatek display PWM driver support Message-ID: <20150512130005.GS6325@pengutronix.de> References: <1431336382-13167-1-git-send-email-yh.huang@mediatek.com> <1431336382-13167-3-git-send-email-yh.huang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1431336382-13167-3-git-send-email-yh.huang@mediatek.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 14:49:40 up 57 days, 41 min, 95 users, load average: 0.03, 0.08, 0.12 User-Agent: Mutt/1.5.21 (2010-09-15) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2458 Lines: 85 On Mon, May 11, 2015 at 05:26:22PM +0800, YH Huang wrote: > + > +static int mtk_disp_pwm_probe(struct platform_device *pdev) > +{ > + struct mtk_disp_pwm_chip *pwm; The struct mtk_disp_pwm_chip * is named 'mpc' in the other functions. For consistency reasons you should do that here aswell. > + struct resource *r; > + int ret; > + > + pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL); > + if (!pwm) > + return -ENOMEM; > + > + pwm->dev = &pdev->dev; > + > + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + pwm->mmio_base = devm_ioremap_resource(&pdev->dev, r); > + if (IS_ERR(pwm->mmio_base)) > + return PTR_ERR(pwm->mmio_base); > + > + pwm->clk_main = devm_clk_get(&pdev->dev, "main"); > + if (IS_ERR(pwm->clk_main)) > + return PTR_ERR(pwm->clk_main); > + pwm->clk_mm = devm_clk_get(&pdev->dev, "mm"); > + if (IS_ERR(pwm->clk_mm)) > + return PTR_ERR(pwm->clk_mm); > + > + ret = clk_prepare_enable(pwm->clk_main); > + if (ret < 0) > + return ret; > + ret = clk_prepare_enable(pwm->clk_mm); > + if (ret < 0) { > + clk_disable_unprepare(pwm->clk_main); > + return ret; > + } > + > + platform_set_drvdata(pdev, pwm); > + > + pwm->chip.dev = &pdev->dev; > + pwm->chip.ops = &mtk_disp_pwm_ops; > + pwm->chip.base = -1; > + pwm->chip.npwm = NUM_PWM; > + > + ret = pwmchip_add(&pwm->chip); > + if (ret < 0) { > + dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); > + return ret; This error path leaves the clocks enabled. > + } > + > + return 0; > +} > + > +static int mtk_disp_pwm_remove(struct platform_device *pdev) > +{ > + struct mtk_disp_pwm_chip *pc = platform_get_drvdata(pdev); > + > + if (WARN_ON(!pc)) > + return -ENODEV; > + > + clk_disable_unprepare(pc->clk_main); > + clk_disable_unprepare(pc->clk_mm); > + > + return pwmchip_remove(&pc->chip); You should first remove the pwmchip and disable the clocks afterwards. Also note that this function can fail. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/