mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
	Krzysztof Opasiak <k.opasiak@samsung.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 1/2] nfc: s3fwrn5: fix order of freeing resources
Date: Thu, 29 Sep 2022 00:51:02 -0700	[thread overview]
Message-ID: <DECCEB72-EE37-4DE4-A734-47A681195BDD@gmail.com> (raw)
In-Reply-To: <1b81d1ec-3050-b983-654b-52c955091274@linaro.org>

On September 29, 2022 12:42:08 AM PDT, Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
>On 29/09/2022 09:37, Dmitry Torokhov wrote:
>> On September 29, 2022 12:27:19 AM PDT, Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> wrote:
>>> On 29/09/2022 09:26, Krzysztof Kozlowski wrote:
>>>> On 29/09/2022 07:04, Dmitry Torokhov wrote:
>>>>> Caution needs to be exercised when mixing together regular and managed
>>>>> resources. In case of this driver devm_request_threaded_irq() should
>>>>> not be used, because it will result in the interrupt being freed too
>>>>> late, and there being a chance that it fires up at an inopportune
>>>>> moment and reference already freed data structures.
>>>>
>>>> Non-devm was so far recommended only for IRQF_SHARED, not for regular
>>>> ones.
>> 
>> If we are absolutely sure there is no possibility of interrupts firing then devm
>> should be ok, but it is much safer not to use it. Or use custom devm actions
>> to free non-managed resources.
>
>I am not sure and the pattern itself is a bit risky, I agree. However
>the driver calls s3fwrn5_remove() which then calls
>s3fwrn5_phy_power_ctrl() which cuts the power via GPIO pin. I assume
>that the hardware should stop generating interrupts at this point.

Ok, fair enough. The GPIO is mandatory, so I guess the chip will be disabled.

>
>> 
>>>> Otherwise you have to fix half of Linux kernel drivers... 
>> 
>> Yes, if they are doing the wrong thing.
>
>What I meant, that this pattern appears pretty often. If we agree that
>this driver has a risky pattern (hardware might not be off after
>remove() callback), then we should maybe document it somewhere and
>include it in usual reviews.

I have been saying that mixing managed and non managed resource is
dangerous for years. Disabling clocks before shutting off interrupts, freeing
memory, etc, is not safe. The best approach with devm is all or nothing.

Thanks.

-- 
Dmitry

      reply	other threads:[~2022-09-29  7:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29  5:04 Dmitry Torokhov
2022-09-29  5:04 ` [PATCH net-next 2/2] nfc: s3fwrn5: use devm_clk_get_optional_enabled() helper Dmitry Torokhov
2022-09-29 14:58   ` Dmitry Torokhov
2022-09-29  7:26 ` [PATCH net-next 1/2] nfc: s3fwrn5: fix order of freeing resources Krzysztof Kozlowski
2022-09-29  7:27   ` Krzysztof Kozlowski
2022-09-29  7:37     ` Dmitry Torokhov
2022-09-29  7:42       ` Krzysztof Kozlowski
2022-09-29  7:51         ` Dmitry Torokhov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DECCEB72-EE37-4DE4-A734-47A681195BDD@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=k.opasiak@samsung.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®