Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2850856imu; Fri, 18 Jan 2019 00:01:14 -0800 (PST) X-Google-Smtp-Source: ALg8bN7h8V9PCpZ3lGYjT26G2CTUc0bmniTtNYubVNOso2JkjQnUHy8RazfPL4hlnVv6s3FTTT60 X-Received: by 2002:a17:902:a5ca:: with SMTP id t10mr18131942plq.139.1547798474551; Fri, 18 Jan 2019 00:01:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547798474; cv=none; d=google.com; s=arc-20160816; b=jPrgB40FGyKa6DlFJHnFUJU0nmCto4N0xW9gf/pKTPLxYqdGMZ23rHlrSlc6UToeKs 1606acHKiZE/CYjdJh4wrAzmPL8ovtm3onkI11gUKhYM7IdDWluUhy0OMuiAV/lVyJQn tyFt/u/dNjuk8klLM8TS+RBKhTjDwELRkp4Hh35LMaQDLkKWVFJCCcqpuE66zCiJ9TIO g+EAEk/vraOg2te4fyycYXLhNAP/YmX2kjuz8IuqRccN8iS3KkILdaEtR+cfWF2RtlS3 qnPido7XKjj9OunVqnnxwFXI/4etKaFegZ0zBs7GOGBBpTtN0128hzDNnUCG54TGDDsP 41ag== 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=fzR4xf/4Capg+XjsJ8UwpbOxzivqoCWwckuqLyc3E4U=; b=SgO3zzt0/uddYTUHEZq5j9GZb/hS+wGKKO5a1GMA1dUWztaQm7i9Ul0U6V7ZqyGABK JDPgNoxIJTIYT8HtwMNLnsF4Z+JgNm6JJcP8wU4W/0/FPFCjXQc7fe98LL3LG+/JmG5s LoCWT22suHW2H8lroNFjIx2gsb4PjQJqx4WKMPxqv3J7Vnsbn7ozchXkmZpJ5OreGvWs T7sMHtAO+lffAAqZ4wpj4m3vH+Sp8Ass6x7Uonjh/0fB2tIesFB6Ot746//teBMY//qc KiTvyHwiTVK4X0MM1EE/oQiAK86dkok7dZatkkCqm6Q9/JXbRC3pt7wdcB1AQEsI+r3t wJkA== 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 32si4167056plg.29.2019.01.18.00.00.56; Fri, 18 Jan 2019 00:01:14 -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 S1727271AbfARH7e (ORCPT + 99 others); Fri, 18 Jan 2019 02:59:34 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:52771 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727167AbfARH7e (ORCPT ); Fri, 18 Jan 2019 02:59:34 -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 1gkP3m-0001Xc-KE; Fri, 18 Jan 2019 08:59:26 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gkP3l-0007kZ-J5; Fri, 18 Jan 2019 08:59:25 +0100 Date: Fri, 18 Jan 2019 08:59:25 +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: <20190118075925.noilab6glzm3cig6@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, 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. I still think Thierry should bless "num-pwms" without vendor prefix. > 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 { Unrelated to this patch: This name is bad. This struct is not used as platform_data and so should better be named mtk_pwm_of_data. While at criticizing existing stuff: I'd prefer pwm_mediatek as common prefix to match the filename. > - unsigned int num_pwms; > + unsigned int num_pwms; /* it should not be used in the future SoCs */ I'd drop this comment in favour of a runtime warning. > 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); This might return NULL which ... > > 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) { ... here then results in a NULL pointer dereference. I think you want if (pc->soc) here. > + 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 (IS_ERR(pc->clks[i])) { > dev_err(&pdev->dev, "clock: %s fail: %ld\n", > @@ -260,7 +269,7 @@ static int mtk_pwm_probe(struct platform_device *pdev) > pc->chip.dev = &pdev->dev; > pc->chip.ops = &mtk_pwm_ops; > pc->chip.base = -1; > - pc->chip.npwm = data->num_pwms; > + pc->chip.npwm = num_pwms; > > ret = pwmchip_add(&pc->chip); > if (ret < 0) { Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |