From: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
To: Ally Heev <allyheev@gmail.com>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.com>,
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>
Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Simon Horman <horms@kernel.org>,
Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH RFT net-next 2/2] idpf: remove __free usage in idpf_virtchnl
Date: Tue, 4 Aug 2026 15:54:55 -0700 [thread overview]
Message-ID: <72754805-575c-4568-9dab-514e1b758847@oss.qualcomm.com> (raw)
In-Reply-To: <20251116-aheev-fix-free-uninitialized-ptrs-ethernet-intel-v1-2-0ddc81be6a4c@gmail.com>
On 11/16/2025 7:56 AM, Ally Heev wrote:
> usage of cleanup attributes is discouraged in net [1], achieve cleanup
> using goto. In this patch though, only uninitialized pointers with __free
> attribute are cleaned as they can cause undefined behavior when they
> go out of scope
>
> Suggested-by: Simon Horman <horms@kernel.org>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/all/aPiG_F5EBQUjZqsl@stanley.mountain/
> Signed-off-by: Ally Heev <allyheev@gmail.com>
>
> [1] https://docs.kernel.org/process/maintainer-netdev.html#using-device-managed-and-cleanup-h-constructs
<SMH>
If using __free() *correctly* gives more readable code, why wouldn't we do it?
The only problem with this function is that it doesn't follow the guidance
from cleanup.h:
* the recommendation is to always define and assign variables in one
* statement and not group variable definitions at the top of the
* function when __free() is used.
>
> Signed-off-by: Ally Heev <allyheev@gmail.com>
> ---
> drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 28 +++++++++++++++++--------
> 1 file changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> index cbb5fa30f5a0ec778c1ee30470da3ca21cc1af24..5b2bf8c3205bc1ea0746f78afa2a24f3f8ad2a8c 100644
> --- a/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> +++ b/drivers/net/ethernet/intel/idpf/idpf_virtchnl.c
> @@ -1012,7 +1012,7 @@ static int idpf_send_get_caps_msg(struct idpf_adapter *adapter)
> */
> static int idpf_send_get_lan_memory_regions(struct idpf_adapter *adapter)
> {
> - struct virtchnl2_get_lan_memory_regions *rcvd_regions __free(kfree);
> + struct virtchnl2_get_lan_memory_regions *rcvd_regions = NULL;
> struct idpf_vc_xn_params xn_params = {
> .vc_op = VIRTCHNL2_OP_GET_LAN_MEMORY_REGIONS,
> .recv_buf.iov_len = IDPF_CTLQ_MAX_BUF_LEN,
> @@ -1029,21 +1029,29 @@ static int idpf_send_get_lan_memory_regions(struct idpf_adapter *adapter)
>
> xn_params.recv_buf.iov_base = rcvd_regions;
> reply_sz = idpf_vc_xn_exec(adapter, &xn_params);
> - if (reply_sz < 0)
> - return reply_sz;
> + if (reply_sz < 0) {
> + err = reply_sz;
> + goto out;
> + }
>
> num_regions = le16_to_cpu(rcvd_regions->num_memory_regions);
> size = struct_size(rcvd_regions, mem_reg, num_regions);
> - if (reply_sz < size)
> - return -EIO;
> + if (reply_sz < size) {
> + err = -EIO;
> + goto out;
> + }
>
> - if (size > IDPF_CTLQ_MAX_BUF_LEN)
> - return -EINVAL;
> + if (size > IDPF_CTLQ_MAX_BUF_LEN) {
> + err = -EINVAL;
> + goto out;
> + }
>
> hw = &adapter->hw;
> hw->lan_regs = kcalloc(num_regions, sizeof(*hw->lan_regs), GFP_KERNEL);
> - if (!hw->lan_regs)
> - return -ENOMEM;
> + if (!hw->lan_regs) {
> + err = -ENOMEM;
> + goto out;
> + }
>
> for (int i = 0; i < num_regions; i++) {
> hw->lan_regs[i].addr_len =
> @@ -1053,6 +1061,8 @@ static int idpf_send_get_lan_memory_regions(struct idpf_adapter *adapter)
> }
> hw->num_lan_regs = num_regions;
>
> +out:
> + kfree(rcvd_regions);
> return err;
> }
>
>
next prev parent reply other threads:[~2026-08-04 22:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-16 15:56 [PATCH RFT net-next 0/2] ethernet: intel: fix freeing uninitialized pointers with __free Ally Heev
2025-11-16 15:56 ` [PATCH RFT net-next 1/2] ice: remove __free usage in ice_flow Ally Heev
2025-11-16 15:56 ` [PATCH RFT net-next 2/2] idpf: remove __free usage in idpf_virtchnl Ally Heev
2026-08-04 22:54 ` Jeff Johnson [this message]
2026-08-04 22:56 ` Jeff Johnson
2026-08-05 11:56 ` __free usage Przemek Kitszel
2026-08-07 14:11 ` Jeff Johnson
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=72754805-575c-4568-9dab-514e1b758847@oss.qualcomm.com \
--to=jeff.johnson@oss.qualcomm.com \
--cc=allyheev@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.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