public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
To: Ciprian Marian Costea <ciprianmarian.costea@oss.nxp.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	imx@lists.linux.dev, NXP Linux Team <s32@nxp.com>,
	Christophe Lizzi <clizzi@redhat.com>,
	Alberto Ruiz <aruizrui@redhat.com>,
	Enric Balletbo <eballetb@redhat.com>
Subject: Re: [PATCH 3/3] can: flexcan: handle S32G2/S32G3 separate interrupt lines
Date: Tue, 19 Nov 2024 20:36:30 +0900	[thread overview]
Message-ID: <7a91c06f-6ea3-4262-82a3-9a1daf481f82@wanadoo.fr> (raw)
In-Reply-To: <f84991f7-66c6-4366-9953-b230761b6b7a@wanadoo.fr>

On 19/11/2024 at 20:26, Vincent Mailhol wrote:
> On 19/11/2024 at 19:01, Ciprian Marian Costea wrote:
>> On 11/19/2024 11:26 AM, Vincent Mailhol wrote:
>>> On 19/11/2024 at 17:10, Ciprian Costea wrote:
> 
> (...)
> 
>>>>   +    if (priv->devtype_data.quirks & FLEXCAN_QUIRK_SECONDARY_MB_IRQ) {
>>>> +        err = request_irq(priv->irq_secondary_mb,
>>>> +                  flexcan_irq, IRQF_SHARED, dev->name, dev);
>>>> +        if (err)
>>>> +            goto out_free_irq_err;
>>>> +    }
>>>
>>> Is the logic here correct?
>>>
>>>    request_irq(priv->irq_err, flexcan_irq, IRQF_SHARED, dev->name, dev);
>>>
>>> is called only if the device has the FLEXCAN_QUIRK_NR_IRQ_3 quirk.
>>>
>>> So, if the device has the FLEXCAN_QUIRK_SECONDARY_MB_IRQ but not the
>>> FLEXCAN_QUIRK_NR_IRQ_3, you may end up trying to free an irq which was
>>> not initialized.
>>>
>>> Did you confirm if it is safe to call free_irq() on an uninitialized irq?
>>>
>>> (and I can see that currently there is no such device with
>>> FLEXCAN_QUIRK_SECONDARY_MB_IRQ but without FLEXCAN_QUIRK_NR_IRQ_3, but
>>> who knows if such device will be introduced in the future?)
>>>
>>
>> Hello Vincent,
>>
>> Thanks for your review. Indeed this seems to be an incorrect logic since
>> I do not want to create any dependency between 'FLEXCAN_QUIRK_NR_IRQ_3'
>> and 'FLEXCAN_QUIRK_SECONDARY_MB_IRQ'.
>>
>> I will change the impacted section to:
>>     if (err) {
>>         if (priv->devtype_data.quirks & FLEXCAN_QUIRK_NR_IRQ_3)
>>             goto out_free_irq_err;
>>         else
>>             goto out_free_irq;
>>     }
> 
> This is better. Alternatively, you could move the check into the label:
> 
>   out_free_irq_err:
>   	if (priv->devtype_data.quirks & FLEXCAN_QUIRK_NR_IRQ_3)
>   		free_irq(priv->irq_err, dev);
> 
> But this is not a strong preference, I let you pick the one which you
> prefer.

On second thought, it is a strong preference. If you keep the

	if (priv->devtype_data.quirks & FLEXCAN_QUIRK_NR_IRQ_3)
		goto out_free_irq_err;
	else
		goto out_free_irq;

then what if more code with a clean-up label is added to flexcan_open()?
I am thinking of this:

  out_free_foo:
  	free(foo);
  out_free_irq_err:
  	free_irq(priv-irq_err, dev);
  out_free_irq_boff:
  	free_irq(priv->irq_boff, dev);

Jumping to out_free_foo would now be incorrect because the
out_free_irq_err label would also be visited.

>>>>       flexcan_chip_interrupts_enable(dev);
>>>>         netif_start_queue(dev);
>>>>         return 0;
>>>>   + out_free_irq_err:
>>>> +    free_irq(priv->irq_err, dev);
>>>>    out_free_irq_boff:
>>>>       free_irq(priv->irq_boff, dev);
>>>>    out_free_irq:
> 
> (...)

Yours sincerely,
Vincent Mailhol


  parent reply	other threads:[~2024-11-19 11:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-19  8:10 [PATCH 0/3] add FlexCAN support for S32G2/S32G3 SoCs Ciprian Costea
2024-11-19  8:10 ` [PATCH 1/3] dt-bindings: can: fsl,flexcan: add S32G2/S32G3 SoC support Ciprian Costea
2024-11-19 19:49   ` Frank Li
2024-11-20  8:45   ` Krzysztof Kozlowski
2024-11-20  9:12     ` Krzysztof Kozlowski
2024-11-20 10:33       ` Ciprian Marian Costea
2024-11-20 13:29         ` Krzysztof Kozlowski
2024-11-20  8:49   ` Marc Kleine-Budde
2024-11-20  9:04     ` Ciprian Marian Costea
2024-11-19  8:10 ` [PATCH 2/3] can: flexcan: add NXP " Ciprian Costea
2024-11-19 19:50   ` Frank Li
2024-11-20  9:01   ` Marc Kleine-Budde
2024-11-20  9:16     ` Ciprian Marian Costea
2024-11-19  8:10 ` [PATCH 3/3] can: flexcan: handle S32G2/S32G3 separate interrupt lines Ciprian Costea
2024-11-19  9:26   ` Vincent Mailhol
2024-11-19 10:01     ` Ciprian Marian Costea
2024-11-19 11:26       ` Vincent Mailhol
2024-11-19 11:28         ` Marc Kleine-Budde
2024-11-19 11:36         ` Vincent Mailhol [this message]
2024-11-19 11:40           ` Ciprian Marian Costea
2024-11-20  8:52   ` Marc Kleine-Budde
2024-11-20  9:01     ` Ciprian Marian Costea
2024-11-20 10:01       ` Marc Kleine-Budde
2024-11-20 10:18         ` Ciprian Marian Costea
2024-11-20 10:29           ` Marc Kleine-Budde
2024-11-20 10:47             ` Ciprian Marian Costea
2024-11-20 10:54               ` Marc Kleine-Budde
2024-11-20 11:02                 ` Ciprian Marian Costea
2024-11-20 11:33                   ` Marc Kleine-Budde
2024-11-20 11:42                     ` Ciprian Marian Costea
2024-11-20 12:06                       ` Marc Kleine-Budde
2024-11-20 12:20   ` Marc Kleine-Budde
2024-11-20 13:38     ` Ciprian Marian Costea

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=7a91c06f-6ea3-4262-82a3-9a1daf481f82@wanadoo.fr \
    --to=mailhol.vincent@wanadoo.fr \
    --cc=andrew+netdev@lunn.ch \
    --cc=aruizrui@redhat.com \
    --cc=ciprianmarian.costea@oss.nxp.com \
    --cc=clizzi@redhat.com \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=eballetb@redhat.com \
    --cc=edumazet@google.com \
    --cc=imx@lists.linux.dev \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=robh@kernel.org \
    --cc=s32@nxp.com \
    /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