Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2857228imu; Fri, 18 Jan 2019 00:07:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN7wQNzUereYs7BX64Gv4S5td+KW79J7donw7IYWQaDvp1a+y6GtpcLTlJNTvTTBbh7V+l6x X-Received: by 2002:a17:902:fa2:: with SMTP id 31mr18342356plz.75.1547798868541; Fri, 18 Jan 2019 00:07:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547798868; cv=none; d=google.com; s=arc-20160816; b=J0eSb8RgyMkrmnszv3Ck8Am2T5dPrKai5teqhJ611zF0eWIH6r2lSk3DKjMGxw0y8h rLpuPEBFTXNzikC4kVrJDtasOR7Jnsa+2QUhvTs8dcv703xx9rrqCfI4Xf0yzgDUrsff qsg6XH2kOUkoVZSYvXoa5dfkBdFf9gA+4EtRnj+74j4mWvOh2eeBnVIp7JAGONWgfO8G lbntii52LIMsw6kPYwfBkfF521taTvcvHIpAIEjd9PKjwkO9R9tAsnJ/1MPbB0GxxJbz HvmdPhxZOPXvhb0kucQlg24kzBtExkCq/34ZGw2fBSS/iejC5M3itcTtn6vctvKy8mMK CaDQ== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/yqGujqPM86EhQEVkRn44GAxpJnNAMrZnvhDGRsxLzk=; b=z/adMSGbrGcM6nXlbLKGndt0tDNnl+0NRsebf4UVPdYoOZOIMOk0h2IIFicsaWZ7h2 QAAZnAF8VPCnnzSpfa0Dti+CD4j24Iy7dllwyD4Gu2YBlLut806FavCK/RbNdesoxl+K FtqNbGfy0Rpvi3BVm/PfbMVFFjSXfZFA4qfl6NQAA6SEXi99OSdL2PW0jkRJGFz2yxNr SevecOqyIt94BHe1W+lBHnYzu9MFoFUkK9rFwr+iQaxHIf4rbEfrb+5Md7LLptQwUgVP 4b9HCussevlQmtiT9ExzJMGMtLIoV6V4UcUX3hmZDN6SwpWyHgCt0QVi4DWrNM92dDJu aPCg== 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 o19si237466pfi.261.2019.01.18.00.07.32; Fri, 18 Jan 2019 00:07:48 -0800 (PST) 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 S1727334AbfARIGB (ORCPT + 99 others); Fri, 18 Jan 2019 03:06:01 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:45345 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727178AbfARIGA (ORCPT ); Fri, 18 Jan 2019 03:06:00 -0500 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gkPA1-0002fI-DN; Fri, 18 Jan 2019 09:05:53 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gkPA0-000151-NJ; Fri, 18 Jan 2019 09:05:52 +0100 Date: Fri, 18 Jan 2019 09:05:52 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Ryder Lee Cc: Thierry Reding , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, Sean Wang , Weijie Gao , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v1 1/5] pwm: mediatek: add a property "mediatek,num-pwms" Message-ID: <20190118080552.ppwgxboh3gt3nasv@pengutronix.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ukl@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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, just realized another issue while looking up a driver detail ... On Fri, Jan 18, 2019 at 11:24:41AM +0800, Ryder Lee wrote: > This adds a property "mediatek,num-pwms" to avoid having an endless > list of compatibles with no differences for the same driver. > > Thus, the driver should have backwards compatibility to older DTs. > > Signed-off-by: Ryder Lee > --- > Changes since v1: add some checks for backwards compatibility. > --- > drivers/pwm/pwm-mediatek.c | 27 ++++++++++++++++++--------- > 1 file changed, 18 insertions(+), 9 deletions(-) > > diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c > index eb6674c..81b7e5e 100644 > --- a/drivers/pwm/pwm-mediatek.c > +++ b/drivers/pwm/pwm-mediatek.c > @@ -55,7 +55,7 @@ enum { > }; > > struct mtk_pwm_platform_data { > - unsigned int num_pwms; > + unsigned int num_pwms; /* it should not be used in the future SoCs */ > bool pwm45_fixup; > bool has_clks; > }; > @@ -226,27 +226,36 @@ static void mtk_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) > > static int mtk_pwm_probe(struct platform_device *pdev) > { > - const struct mtk_pwm_platform_data *data; > + struct device_node *np = pdev->dev.of_node; > struct mtk_pwm_chip *pc; > struct resource *res; > - unsigned int i; > + unsigned int i, num_pwms; > int ret; > > pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL); > if (!pc) > return -ENOMEM; > > - data = of_device_get_match_data(&pdev->dev); > - if (data == NULL) > - return -EINVAL; > - pc->soc = data; > + pc->soc = of_device_get_match_data(&pdev->dev); > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > pc->regs = devm_ioremap_resource(&pdev->dev, res); > if (IS_ERR(pc->regs)) > return PTR_ERR(pc->regs); > > - for (i = 0; i < data->num_pwms + 2 && pc->soc->has_clks; i++) { > + /* Check if we have set 'num-pwms' in DTs. */ > + ret = of_property_read_u32(np, "mediatek,num-pwms", &num_pwms); > + if (ret < 0) { > + /* If no, fallback to use SoC data for backwards compatibility. */ > + if (pc->soc->num_pwms) { > + num_pwms = pc->soc->num_pwms; > + } else { > + dev_err(&pdev->dev, "failed to get pwm number: %d\n", ret); > + return ret; > + } > + } > + > + for (i = 0; i < num_pwms + 2 && pc->soc->has_clks; i++) { > pc->clks[i] = devm_clk_get(&pdev->dev, mtk_pwm_clk_name[i]); If a dt contains mediatek,num-pwms = <17>; you're accessing pc->clks[18] which is an out-of-bounds access, so better check the limit or allocate the clks array dynamically. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |