From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E051C433F5 for ; Thu, 18 Nov 2021 18:11:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 040AF6138F for ; Thu, 18 Nov 2021 18:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231738AbhKRSOJ (ORCPT ); Thu, 18 Nov 2021 13:14:09 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:4109 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230446AbhKRSOJ (ORCPT ); Thu, 18 Nov 2021 13:14:09 -0500 Received: from fraeml702-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Hw7BP5mSyz67HxV; Fri, 19 Nov 2021 02:10:21 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml702-chm.china.huawei.com (10.206.15.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.20; Thu, 18 Nov 2021 19:11:06 +0100 Received: from localhost (10.52.127.148) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 18 Nov 2021 18:11:06 +0000 Date: Thu, 18 Nov 2021 18:11:03 +0000 From: Jonathan Cameron To: Ahmad Fatoum CC: Olivier Moysan , Alexandre Torgue , Fabrice Gasnier , Jonathan Cameron , Lars-Peter Clausen , Mauro Carvalho Chehab , Maxime Coquelin , "Wan Jiabing" , Xu Wang , , , , Subject: Re: [PATCH] iio: adc: stm32: fix null pointer on defer_probe error Message-ID: <20211118181103.000054c7@Huawei.com> In-Reply-To: <45a5129a-c0b1-4a07-aef8-d6e0845c7b1a@pengutronix.de> References: <20211118123952.15383-1-olivier.moysan@foss.st.com> <45a5129a-c0b1-4a07-aef8-d6e0845c7b1a@pengutronix.de> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.52.127.148] X-ClientProxiedBy: lhreml749-chm.china.huawei.com (10.201.108.199) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Thu, 18 Nov 2021 13:51:44 +0100 Ahmad Fatoum wrote: > Hello Olivier, > > On 18.11.21 13:39, Olivier Moysan wrote: > > dev_err_probe() calls __device_set_deferred_probe_reason() > > on -EPROBE_DEFER error. > > If device pointer to driver core private structure is not initialized, > > a null pointer error occurs. > > This pointer is set too late on iio_device_register() call, for iio device. > > Even if it were set earlier, you should call dev_err_probe with the dev of > the probe that's currently running. Not any other devices you created since > then. +1 on that > > > So use parent device instead for dev_err_probe() call. > > > > Fixes: 0e346b2cfa85 ("iio: adc: stm32-adc: add vrefint calibration support") > > No line break between these two tags. Greg will reject a pull if there is one (and 0-day probably complain about it...) Jonathan > > Signed-off-by: Olivier Moysan > > --- > > drivers/iio/adc/stm32-adc.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c > > index 7f1fb36c747c..14c7c9d390e8 100644 > > --- a/drivers/iio/adc/stm32-adc.c > > +++ b/drivers/iio/adc/stm32-adc.c > > @@ -217,6 +217,7 @@ struct stm32_adc_cfg { > > > > /** > > * struct stm32_adc - private data of each ADC IIO instance > > + * dev: parent device > > * @common: reference to ADC block common data > > * @offset: ADC instance register offset in ADC block > > * @cfg: compatible configuration data > > @@ -243,6 +244,7 @@ struct stm32_adc_cfg { > > * @int_ch: internal channel indexes array > > */ > > struct stm32_adc { > > + struct device *dev; > > Can't you use the parent pointer of the indio_dev? > > > struct stm32_adc_common *common; > > u32 offset; > > const struct stm32_adc_cfg *cfg; > > @@ -1986,8 +1988,7 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n > > /* Get calibration data for vrefint channel */ > > ret = nvmem_cell_read_u16(&indio_dev->dev, "vrefint", &vrefint); > > if (ret && ret != -ENOENT) { > > - return dev_err_probe(&indio_dev->dev, ret, > > - "nvmem access error\n"); > > + return dev_err_probe(adc->dev, ret, "nvmem access error\n"); > > } > > if (ret == -ENOENT) > > dev_dbg(&indio_dev->dev, "vrefint calibration not found\n"); > > @@ -2221,6 +2222,7 @@ static int stm32_adc_probe(struct platform_device *pdev) > > init_completion(&adc->completion); > > adc->cfg = (const struct stm32_adc_cfg *) > > of_match_device(dev->driver->of_match_table, dev)->data; > > + adc->dev = &pdev->dev; > > There's struct device *dev = &pdev->dev; defined earlier, so you can use dev instead. > > > > > indio_dev->name = dev_name(&pdev->dev); > > indio_dev->dev.of_node = pdev->dev.of_node; > > > > Cheers, > Ahmad > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DC15C433F5 for ; Thu, 18 Nov 2021 18:12:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC0936138F for ; Thu, 18 Nov 2021 18:12:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DC0936138F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=Huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:CC:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ihBLpuVPX8zSo8/rd2RnTD7ym8x6/QwfF9oqmuIBzOU=; b=Crjt1W2QlgEUEE dqtXyQfayvI9jTO71eUu5x2m2HD0yvG9f+eLJSN9xd0UK2UeqqO2VrhEPdVbezW6MoSP7FLmxpsPm kLccpeR9WLTXEYGFllqSj7O6LsnML0evzoX0mmn1yPrS2AcH1qlxbUEoNCPguMklqyD4SsDAjD/Mo OXVs/R301LWuSHUap6rwUvWM48TGtViGvVLcrCRBfgIuZMY2/fFZGbhPpNuMjZL8PV/4iTyUmudIb AkECZq/X8KyZ9qxx1TurfNBM5LnqXNz+U+RoWS430iNXPiCLHyOQMGVWRGUYwSvjdg5DSoZPG9AjG u73g7Bml47LNgAys+4Rw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnlsP-008W7E-5x; Thu, 18 Nov 2021 18:11:13 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnlsL-008W64-0D for linux-arm-kernel@lists.infradead.org; Thu, 18 Nov 2021 18:11:10 +0000 Received: from fraeml702-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Hw7BP5mSyz67HxV; Fri, 19 Nov 2021 02:10:21 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml702-chm.china.huawei.com (10.206.15.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.20; Thu, 18 Nov 2021 19:11:06 +0100 Received: from localhost (10.52.127.148) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 18 Nov 2021 18:11:06 +0000 Date: Thu, 18 Nov 2021 18:11:03 +0000 From: Jonathan Cameron To: Ahmad Fatoum CC: Olivier Moysan , Alexandre Torgue , Fabrice Gasnier , Jonathan Cameron , Lars-Peter Clausen , Mauro Carvalho Chehab , Maxime Coquelin , "Wan Jiabing" , Xu Wang , , , , Subject: Re: [PATCH] iio: adc: stm32: fix null pointer on defer_probe error Message-ID: <20211118181103.000054c7@Huawei.com> In-Reply-To: <45a5129a-c0b1-4a07-aef8-d6e0845c7b1a@pengutronix.de> References: <20211118123952.15383-1-olivier.moysan@foss.st.com> <45a5129a-c0b1-4a07-aef8-d6e0845c7b1a@pengutronix.de> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; i686-w64-mingw32) MIME-Version: 1.0 X-Originating-IP: [10.52.127.148] X-ClientProxiedBy: lhreml749-chm.china.huawei.com (10.201.108.199) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211118_101109_375944_636D042D X-CRM114-Status: GOOD ( 25.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 18 Nov 2021 13:51:44 +0100 Ahmad Fatoum wrote: > Hello Olivier, > > On 18.11.21 13:39, Olivier Moysan wrote: > > dev_err_probe() calls __device_set_deferred_probe_reason() > > on -EPROBE_DEFER error. > > If device pointer to driver core private structure is not initialized, > > a null pointer error occurs. > > This pointer is set too late on iio_device_register() call, for iio device. > > Even if it were set earlier, you should call dev_err_probe with the dev of > the probe that's currently running. Not any other devices you created since > then. +1 on that > > > So use parent device instead for dev_err_probe() call. > > > > Fixes: 0e346b2cfa85 ("iio: adc: stm32-adc: add vrefint calibration support") > > No line break between these two tags. Greg will reject a pull if there is one (and 0-day probably complain about it...) Jonathan > > Signed-off-by: Olivier Moysan > > --- > > drivers/iio/adc/stm32-adc.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c > > index 7f1fb36c747c..14c7c9d390e8 100644 > > --- a/drivers/iio/adc/stm32-adc.c > > +++ b/drivers/iio/adc/stm32-adc.c > > @@ -217,6 +217,7 @@ struct stm32_adc_cfg { > > > > /** > > * struct stm32_adc - private data of each ADC IIO instance > > + * dev: parent device > > * @common: reference to ADC block common data > > * @offset: ADC instance register offset in ADC block > > * @cfg: compatible configuration data > > @@ -243,6 +244,7 @@ struct stm32_adc_cfg { > > * @int_ch: internal channel indexes array > > */ > > struct stm32_adc { > > + struct device *dev; > > Can't you use the parent pointer of the indio_dev? > > > struct stm32_adc_common *common; > > u32 offset; > > const struct stm32_adc_cfg *cfg; > > @@ -1986,8 +1988,7 @@ static int stm32_adc_populate_int_ch(struct iio_dev *indio_dev, const char *ch_n > > /* Get calibration data for vrefint channel */ > > ret = nvmem_cell_read_u16(&indio_dev->dev, "vrefint", &vrefint); > > if (ret && ret != -ENOENT) { > > - return dev_err_probe(&indio_dev->dev, ret, > > - "nvmem access error\n"); > > + return dev_err_probe(adc->dev, ret, "nvmem access error\n"); > > } > > if (ret == -ENOENT) > > dev_dbg(&indio_dev->dev, "vrefint calibration not found\n"); > > @@ -2221,6 +2222,7 @@ static int stm32_adc_probe(struct platform_device *pdev) > > init_completion(&adc->completion); > > adc->cfg = (const struct stm32_adc_cfg *) > > of_match_device(dev->driver->of_match_table, dev)->data; > > + adc->dev = &pdev->dev; > > There's struct device *dev = &pdev->dev; defined earlier, so you can use dev instead. > > > > > indio_dev->name = dev_name(&pdev->dev); > > indio_dev->dev.of_node = pdev->dev.of_node; > > > > Cheers, > Ahmad > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel