netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Jianbo Liu <jianbol@nvidia.com>
Cc: Tariq Toukan <tariqt@nvidia.com>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Saeed Mahameed <saeedm@nvidia.com>,
	"Leon Romanovsky" <leon@kernel.org>,
	Mark Bloch <mbloch@nvidia.com>, <netdev@vger.kernel.org>,
	<linux-rdma@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Gal Pressman <gal@nvidia.com>, Jakub Kicinski <kuba@kernel.org>
Subject: Re: [PATCH net 1/3] net/mlx5e: Harden uplink netdev access against device unbind
Date: Fri, 12 Sep 2025 13:07:51 +0200	[thread overview]
Message-ID: <dbabdfb6-e6cc-40a4-97ee-fcfd29371e8e@intel.com> (raw)
In-Reply-To: <9bbac284-48b8-4377-85f9-9dd3c60410cf@nvidia.com>

On 9/11/25 09:09, Jianbo Liu wrote:
> 
> 
> On 9/11/2025 8:45 AM, Jakub Kicinski wrote:
>> On Wed, 10 Sep 2025 11:23:09 +0800 Jianbo Liu wrote:
>>> On 9/10/2025 9:23 AM, Jakub Kicinski wrote:
>>>> On Mon, 8 Sep 2025 13:07:04 +0300 Tariq Toukan wrote:
>>>>> +    struct net_device *netdev = mlx5_uplink_netdev_get(dev);
>>>>> +    struct mlx5e_priv *priv;
>>>>> +    int err;
>>>>> +
>>>>> +    if (!netdev)
>>>>> +        return 0;
>>>>
>>>> Please don't call in variable init functions which require cleanup
>>>> or error checking.
>>>
>>> But in this function, a NULL return from mlx5_uplink_netdev_get is a
>>> valid condition where it should simply return 0. No cleanup or error
>>> check is needed.
>>
>> You have to check if it succeeded, and if so, you need to clean up
>> later. Do no hide meaningful code in variable init.
> 
> My focus was on the NULL case, but I see now that the real issue is 
> ensuring the corresponding cleanup (_put) happens on the successful 
> path. Hiding the _get call in the initializer makes that less clear.
> 
> I will refactor the code to follow the correct pattern, like this:
> 
> struct net_device *netdev;
> 
> netdev = mlx5_uplink_netdev_get(dev);
> if (!netdev)
>      return 0;
> 
> Thank you for the explanation.
> 

that would be much better, and make it obvious that there is
matched get() and put() calls

would be also great to minify stacktrace
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#backtraces-in-commit-messages


  reply	other threads:[~2025-09-12 11:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 10:07 [PATCH net 0/3] mlx5e misc fixes 2025-09-08 Tariq Toukan
2025-09-08 10:07 ` [PATCH net 1/3] net/mlx5e: Harden uplink netdev access against device unbind Tariq Toukan
2025-09-10  1:23   ` Jakub Kicinski
2025-09-10  3:23     ` Jianbo Liu
2025-09-11  0:45       ` Jakub Kicinski
2025-09-11  7:09         ` Jianbo Liu
2025-09-12 11:07           ` Przemek Kitszel [this message]
2025-09-15  0:59             ` Jianbo Liu
2025-09-08 10:07 ` [PATCH net 2/3] net/mlx5e: Prevent entering switchdev mode with inconsistent netns Tariq Toukan
2025-09-10  1:23   ` Jakub Kicinski
2025-09-10  3:01     ` Jianbo Liu
2025-09-11  0:48       ` Jakub Kicinski
2025-09-11  7:48         ` Jianbo Liu
2025-09-12  0:11           ` Jakub Kicinski
2025-09-12  1:12             ` Jianbo Liu
2025-09-08 10:07 ` [PATCH net 3/3] net/mlx5e: Add a miss level for ipsec crypto offload Tariq Toukan

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=dbabdfb6-e6cc-40a4-97ee-fcfd29371e8e@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=jianbol@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.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;
as well as URLs for NNTP newsgroup(s).