Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2942926imu; Fri, 18 Jan 2019 01:57:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN7mjTUDX4M8KDrI1UU8Ucm7aFsFsbQLZYQady6DzUXvZsWpyJZ8FYFRyNH5nI8+vjjp6/vJ X-Received: by 2002:a17:902:4681:: with SMTP id p1mr19012031pld.184.1547805448460; Fri, 18 Jan 2019 01:57:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547805448; cv=none; d=google.com; s=arc-20160816; b=ZOSrD870wbPkTP9US/fMDlPARHGjM1sWTwPVsu+JRV5qP/d12auNq7yARTeD+1RaoS eF+mGoiKqLYzg7eldRl19ZBywJLjYLQFPxftjjApKRFXWaf/wzv/qWJcD0EM2gl7azZH 3X0G24NNuTrNe1DmIp7CCmgPoD53te1/Xs+Cw8jgVhoC9Jilp3mmvY7KHR7YU0IeMgta 9XMBsVr45Cs3A5R2+CLyvG69rSOPmYeMMOAya7fG8RfYq2MqF/y6h+RZwNX4/PVF/iyv zkcVTwEHLfu8S1uSp4eMUFb3NxgFg9aOzDdPYD4bjc/9ex5vpn6AlXMjjrCmIJyOjJvs wymw== 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=ztXVcapsA7IWgLR5XFRgF/2k9KM4i2oH8M/hdKsBRdE=; b=TUFnd4hDVko0vzic+ilj+su1rbJNQ8sSdTtToMVbbdz8kaPEkMUwVzPchrTVdOz0Bl LquDPxTMS2GUA5vmqIAgyfD75Ofh4IXc8mnQ319WJsXYb1ngAAOyqsqShlJS1uiy2AUE AQnBc5A2njM4TD8+Tu3tOvh5/ObZvEuf6uDePGaMVoqgysvPQdxV4pHf06wbLZhm5S1D rpmJPq4ofJ+Q07c5shPmwsVdnylxJKtqpKeOUxFZjjomogQisZMcT8ormwWq1E0SVvZU ZhQSYmsebXNYzEhzDzV8vkFdOEMtO4LAOSnlfwXfirdk0jOhjKaJsn/kNrwxQW0/Es6q iMLQ== 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 e37si4069127plb.172.2019.01.18.01.57.10; Fri, 18 Jan 2019 01:57:28 -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 S1727148AbfARJxV (ORCPT + 99 others); Fri, 18 Jan 2019 04:53:21 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:46589 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbfARJxV (ORCPT ); Fri, 18 Jan 2019 04:53:21 -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 1gkQpu-00073h-0Z; Fri, 18 Jan 2019 10:53:14 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gkQpt-0006HG-KN; Fri, 18 Jan 2019 10:53:13 +0100 Date: Fri, 18 Jan 2019 10:53:13 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Ryder Lee Cc: linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, Sean Wang , Weijie Gao , linux-kernel@vger.kernel.org, Thierry Reding , 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: <20190118095313.pbpdn43hd76khg2x@pengutronix.de> References: <20190118075925.noilab6glzm3cig6@pengutronix.de> <1547804574.8124.6.camel@mtkswgap22> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1547804574.8124.6.camel@mtkswgap22> 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 Ryder, On Fri, Jan 18, 2019 at 05:42:54PM +0800, Ryder Lee wrote: > On Fri, 2019-01-18 at 08:59 +0100, Uwe Kleine-K?nig wrote: > > 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. > > Okay. > > > > 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. > > I think we can take care about that in another patch. That's what I wanted to say, right. Do you follow up? > > > - 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. > > Sorry, I can't get you here. I'd do a dev_warn(dev, "dt didn't specify number of PWMs, falling back to %d\n", pc->soc->num_pwms); to make people aware that updating the dt would be nice. > > > > 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 ... > > The only way to call probe() is to match an entry in > mtk_pwm_of_match[], so match cannot be NULL. (Theoretically the driver can be probed by device name, but that is not what I meant here.). You're right, as long as all entries in mtk_pwm_of_match have a non-NULL .data entry, you're fine. I somehow thought there might be some without one. I wouldn't oppose to check for that anyhow as a defensive measure. > > > [...] > > > + /* 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 > > So we have no chance to get a NULL pointer, right? Ack. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |