Message ID | 20230313205029.1881745-1-risca@dalakolonin.se |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1409604wrd; Mon, 13 Mar 2023 14:12:17 -0700 (PDT) X-Google-Smtp-Source: AK7set+1KbgNkDojFG0P9N1AwpiyVIyAldj3d5s63MO1HifwLu3ibyX/PcqHkfuH2n+xYg39zigR X-Received: by 2002:a17:90b:4b44:b0:237:72e5:61bd with SMTP id mi4-20020a17090b4b4400b0023772e561bdmr37219175pjb.49.1678741937103; Mon, 13 Mar 2023 14:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678741937; cv=none; d=google.com; s=arc-20160816; b=CTLI2rMWN8JHNF1g3EBgcugQDk5+lWpRibzyiJOPAVCj691NleVxqUk8NBL9wzn7GN /wHMNUFqhmcYXUm1Ni6Vrzr+AigiiAlat4fq0TipkTyX93bTd8ipjwLGWYissY/MrnlD QNOH00Sr6WRcrPDy0cz1gkg9l0EiHBIey57YK99ur9TxNGP6FkKhv96XfgIMNR4/kAdW HpE/MNQPBagtiAtzLhePs8CqVxNw4xrluYFlpMbMx90x52mg/3CQ47+nwG6MIXygeDdD z8BC+VjDwzfWgWuDxuh3mWcodHKjUrsTk408MGO/g95OXcLmSLNN4D0g0gtVf/TF7PnZ YPtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=44n+TAkBaWHGhZd5jVqYIZZmjHKBgDRlsRmSjvMgBhg=; b=nzVqFCY2iAuQhAlJ/m+lDPaaOrTL3d7DpVLmh8ISrzJaecx+oZs9Hp87OGzq3Tvdu1 SjORcBHOUnWIW1vc3I7rAWSQuAPUU7FqyjAehADG8gor58KrcXMGq/CYG1gGS5qFeqw4 JNQIpXKNLvyfbuuUEYIUv2o9FoRMt2hsMalxHA0Q6OERaZBdepMKwGOowCdAEC2G9lno pyNFfzEsPJdRrMz98knWPow8Mj3omOBmx8wGg3NCvIS9uZ3oSkV5M2waE5w2RLcv3UYo qI7hHnTzLgFScnnn+00n04T3j/2c82nD8Tbers91870tUMw77wX3CrIhOWMn0vC6Z9C/ b84Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ge16-20020a17090b0e1000b0023a8d7dcb05si651510pjb.59.2023.03.13.14.12.04; Mon, 13 Mar 2023 14:12:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229896AbjCMU53 convert rfc822-to-8bit (ORCPT <rfc822;realc9580@gmail.com> + 99 others); Mon, 13 Mar 2023 16:57:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229516AbjCMU51 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 13 Mar 2023 16:57:27 -0400 X-Greylist: delayed 402 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 13 Mar 2023 13:57:25 PDT Received: from ste-pvt-msa1.bahnhof.se (ste-pvt-msa1.bahnhof.se [213.80.101.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6402882364; Mon, 13 Mar 2023 13:57:24 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTP id D7C1E3F3C3; Mon, 13 Mar 2023 21:50:39 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Score: -1.899 X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_05,RCVD_IN_DNSWL_LOW, SPF_FAIL,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 Received: from ste-pvt-msa1.bahnhof.se ([127.0.0.1]) by localhost (ste-pvt-msa1.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CFHsA3PtJ1mI; Mon, 13 Mar 2023 21:50:39 +0100 (CET) Received: by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id CD7213F380; Mon, 13 Mar 2023 21:50:38 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 05E668E68A; Mon, 13 Mar 2023 20:50:38 +0000 (UTC) Received: from zimbra.dalakolonin.se ([127.0.0.1]) by localhost (zimbra.dalakolonin.se [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id sFmyATpvFeIT; Mon, 13 Mar 2023 20:50:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 35D2B8E683; Mon, 13 Mar 2023 20:50:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at dalakolonin.se Received: from zimbra.dalakolonin.se ([127.0.0.1]) by localhost (zimbra.dalakolonin.se [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id UJ0ZAeiQBeJ8; Mon, 13 Mar 2023 20:50:36 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id C98C08E680; Mon, 13 Mar 2023 20:50:36 +0000 (UTC) From: =?utf-8?q?Patrik_Dahlstr=C3=B6m?= <risca@dalakolonin.se> To: jic23@kernel.org, lars@metafoo.de, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, hns@goldelico.com Cc: =?utf-8?q?Patrik_Dahlstr=C3=B6m?= <risca@dalakolonin.se> Subject: [PATCH] iio: adc: palmas_gpadc: fix NULL dereference on rmmod Date: Mon, 13 Mar 2023 21:50:29 +0100 Message-Id: <20230313205029.1881745-1-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760288504979180229?= X-GMAIL-MSGID: =?utf-8?q?1760288504979180229?= |
Series |
iio: adc: palmas_gpadc: fix NULL dereference on rmmod
|
|
Commit Message
Patrik Dahlström
March 13, 2023, 8:50 p.m. UTC
Calling dev_to_iio_dev() on a platform device pointer is undefined and
will make adc NULL.
Signed-off-by: Patrik Dahlström <risca@dalakolonin.se>
---
drivers/iio/adc/palmas_gpadc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mon, 13 Mar 2023 21:50:29 +0100 Patrik Dahlström <risca@dalakolonin.se> wrote: > Calling dev_to_iio_dev() on a platform device pointer is undefined and > will make adc NULL. > > Signed-off-by: Patrik Dahlström <risca@dalakolonin.se> Hi Patrik, Looks good so applied to the fixes-togreg branch of iio.git. Whilst we are here, this would be a trivial driver to take fully device managed. The only slightly messy bit is that it would need a devm_add_action_or_reset() + custom callback to handle the device_wakeup_enable(). On the off chance you can test it I'll send a patch in a few mins. Note that will depend on this one going up stream first and that I haven't done more than build test it. Thanks, Jonathan > --- > drivers/iio/adc/palmas_gpadc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c > index 61e80bf3d05e..6db6f3bc768a 100644 > --- a/drivers/iio/adc/palmas_gpadc.c > +++ b/drivers/iio/adc/palmas_gpadc.c > @@ -638,7 +638,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) > > static int palmas_gpadc_remove(struct platform_device *pdev) > { > - struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); > + struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); > struct palmas_gpadc *adc = iio_priv(indio_dev); > > if (adc->wakeup1_enable || adc->wakeup2_enable)
On Sat, Mar 18, 2023 at 04:30:33PM +0000, Jonathan Cameron wrote: > On Mon, 13 Mar 2023 21:50:29 +0100 > Patrik Dahlström <risca@dalakolonin.se> wrote: > > > Calling dev_to_iio_dev() on a platform device pointer is undefined and > > will make adc NULL. > > > > Signed-off-by: Patrik Dahlström <risca@dalakolonin.se> > > Hi Patrik, > > Looks good so applied to the fixes-togreg branch of iio.git. > > Whilst we are here, this would be a trivial driver to take fully device > managed. The only slightly messy bit is that it would need > a devm_add_action_or_reset() + custom callback to handle the > device_wakeup_enable(). > > On the off chance you can test it I'll send a patch in a few mins. > Note that will depend on this one going up stream first and that > I haven't done more than build test it. I got the patch and it looks good, but it will take a few days before I have the time to test it. I have some more patches coming for this driver to configure the adc thresholds from userspace, employing the iio channel event subsystem, but they need a bit more work. In particular, to ensure backwards compatibility with the adc_wakeupX_data platform data. However, I don't see this platform data being used by anyone. How important is it to retain support for adc_wakeupX_data? > > Thanks, > > Jonathan Thank you for going the extra mile :) > > > > --- > > drivers/iio/adc/palmas_gpadc.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c > > index 61e80bf3d05e..6db6f3bc768a 100644 > > --- a/drivers/iio/adc/palmas_gpadc.c > > +++ b/drivers/iio/adc/palmas_gpadc.c > > @@ -638,7 +638,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) > > > > static int palmas_gpadc_remove(struct platform_device *pdev) > > { > > - struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); > > + struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); > > struct palmas_gpadc *adc = iio_priv(indio_dev); > > > > if (adc->wakeup1_enable || adc->wakeup2_enable) >
On Sat, 18 Mar 2023 20:22:53 +0100 Patrik Dahlström <risca@dalakolonin.se> wrote: > On Sat, Mar 18, 2023 at 04:30:33PM +0000, Jonathan Cameron wrote: > > On Mon, 13 Mar 2023 21:50:29 +0100 > > Patrik Dahlström <risca@dalakolonin.se> wrote: > > > > > Calling dev_to_iio_dev() on a platform device pointer is undefined and > > > will make adc NULL. > > > > > > Signed-off-by: Patrik Dahlström <risca@dalakolonin.se> > > > > Hi Patrik, > > > > Looks good so applied to the fixes-togreg branch of iio.git. > > > > Whilst we are here, this would be a trivial driver to take fully device > > managed. The only slightly messy bit is that it would need > > a devm_add_action_or_reset() + custom callback to handle the > > device_wakeup_enable(). > > > > On the off chance you can test it I'll send a patch in a few mins. > > Note that will depend on this one going up stream first and that > > I haven't done more than build test it. > I got the patch and it looks good, but it will take a few days before I > have the time to test it. > > I have some more patches coming for this driver to configure the adc > thresholds from userspace, employing the iio channel event subsystem, but > they need a bit more work. In particular, to ensure backwards compatibility > with the adc_wakeupX_data platform data. However, I don't see this platform > data being used by anyone. > How important is it to retain support for adc_wakeupX_data? It's a somewhat unusual feature, so I doubt it was implemented without someone needing it. However as you observe there is no upstream user. As it is causing you problems, I'd just rip out the palmas_adc_platform_data completely and see if anyone objects. You can do that as a standalone patch prior to posting your events stuff if you like. Or hopefully H. Nikolaus Schaller might be able to give us some background on why that feature is there but not used. > > > > Thanks, > > > > Jonathan > > Thank you for going the extra mile :) No problem. I jumped on the opportunity to get it tested - takes way longer than writing a little patch like that ;) Jonathan > > > > > > > --- > > > drivers/iio/adc/palmas_gpadc.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c > > > index 61e80bf3d05e..6db6f3bc768a 100644 > > > --- a/drivers/iio/adc/palmas_gpadc.c > > > +++ b/drivers/iio/adc/palmas_gpadc.c > > > @@ -638,7 +638,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) > > > > > > static int palmas_gpadc_remove(struct platform_device *pdev) > > > { > > > - struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); > > > + struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); > > > struct palmas_gpadc *adc = iio_priv(indio_dev); > > > > > > if (adc->wakeup1_enable || adc->wakeup2_enable) > >
Hi there, > Am 19.03.2023 um 16:32 schrieb Jonathan Cameron <jic23@kernel.org>: > > On Sat, 18 Mar 2023 20:22:53 +0100 > Patrik Dahlström <risca@dalakolonin.se> wrote: > >> On Sat, Mar 18, 2023 at 04:30:33PM +0000, Jonathan Cameron wrote: >>> On Mon, 13 Mar 2023 21:50:29 +0100 >>> Patrik Dahlström <risca@dalakolonin.se> wrote: >>> >>>> Calling dev_to_iio_dev() on a platform device pointer is undefined and >>>> will make adc NULL. >>>> >>>> Signed-off-by: Patrik Dahlström <risca@dalakolonin.se> >>> >>> Hi Patrik, >>> >>> Looks good so applied to the fixes-togreg branch of iio.git. >>> >>> Whilst we are here, this would be a trivial driver to take fully device >>> managed. The only slightly messy bit is that it would need >>> a devm_add_action_or_reset() + custom callback to handle the >>> device_wakeup_enable(). >>> >>> On the off chance you can test it I'll send a patch in a few mins. >>> Note that will depend on this one going up stream first and that >>> I haven't done more than build test it. >> I got the patch and it looks good, but it will take a few days before I >> have the time to test it. >> >> I have some more patches coming for this driver to configure the adc >> thresholds from userspace, Yes, that is a useful feature. >> employing the iio channel event subsystem, but >> they need a bit more work. In particular, to ensure backwards compatibility >> with the adc_wakeupX_data platform data. However, I don't see this platform >> data being used by anyone. >> How important is it to retain support for adc_wakeupX_data? > > It's a somewhat unusual feature, so I doubt it was implemented without someone > needing it. However as you observe there is no upstream user. > > As it is causing you problems, I'd just rip out the palmas_adc_platform_data > completely and see if anyone objects. You can do that as a standalone patch > prior to posting your events stuff if you like. Or hopefully > H. Nikolaus Schaller might be able to give us some background on why > that feature is there but not used. I also have no idea. The original author was Pradeep Goudagunta <pgoudagunta@nvidia.com> and I just copied it from https://android.googlesource.com/kernel/tegra/+/aaabb2e045f31e5a970109ffdaae900dd403d17e/drivers/staging/iio/adc/palmas_gpadc.c polished the code and made it compile & work some years ago. So it may have been useful in a some Tegra Android kernel from 2013. Maybe it is for special power management (at least that is how I interpret the "wakeup"). But I found some hint which device it is good for: https://lore.kernel.org/all/1379509642-19227-2-git-send-email-ldewangan@nvidia.com/T/ "PALMAS PMIC is used on Dalmore platform." https://docs.nvidia.com/gameworks/content/devices/dalmore_devkit_main.htm And there seems to be an upstream DTS: arch/arm/boot/dts/tegra114-dalmore.dts but without gpadc support. That is quite common that upstream DTS are incomplete so we can't deduce that there are no users of a feature. BR, Nikolaus > >>> >>> Thanks, >>> >>> Jonathan >> >> Thank you for going the extra mile :) > > No problem. I jumped on the opportunity to get it tested - takes way longer > than writing a little patch like that ;) > > Jonathan > >>> >>> >>>> --- >>>> drivers/iio/adc/palmas_gpadc.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c >>>> index 61e80bf3d05e..6db6f3bc768a 100644 >>>> --- a/drivers/iio/adc/palmas_gpadc.c >>>> +++ b/drivers/iio/adc/palmas_gpadc.c >>>> @@ -638,7 +638,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) >>>> >>>> static int palmas_gpadc_remove(struct platform_device *pdev) >>>> { >>>> - struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); >>>> + struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); >>>> struct palmas_gpadc *adc = iio_priv(indio_dev); >>>> >>>> if (adc->wakeup1_enable || adc->wakeup2_enable) >>> >
diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index 61e80bf3d05e..6db6f3bc768a 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -638,7 +638,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) static int palmas_gpadc_remove(struct platform_device *pdev) { - struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); + struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); struct palmas_gpadc *adc = iio_priv(indio_dev); if (adc->wakeup1_enable || adc->wakeup2_enable)