mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: longlong yan <yanlonglong@kylinos.cn>,
	valentina.manea.m@gmail.com, shuah@kernel.org,
	gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] usbip: add NULL check for calloc in usbip_exported_device_new
Date: Tue, 22 Sep 2026 04:04:23 -0600	[thread overview]
Message-ID: <b37401c1-b6db-4746-9f6a-af25e9f30829@linuxfoundation.org> (raw)
In-Reply-To: <20260817060618.749-1-yanlonglong@kylinos.cn>

On 8/17/26 00:06, longlong yan wrote:
> Add a NULL check for the return value of calloc() in
> usbip_exported_device_new(). If calloc() fails and returns NULL,
> the subsequent dereference of edev->sudev would cause a NULL
> pointer dereference.
> 
> Also fix the error path at the 'err' label to check edev before
> dereferencing edev->sudev. Without this fix, if calloc() fails and
> jumps to 'err', the code would dereference NULL when checking
> edev->sudev.
> 

It is theoretically possible for calloc() to fail, however how often
does it fail and were you able to make this allocation to fail?

If not, how did you test this patch? In any case, I am not going to
take this patch and all the other patches you sent adding checks to
calloc() calls in other places in usbip tool.

> Signed-off-by: longlong yan <yanlonglong@kylinos.cn>
> ---
>   tools/usb/usbip/libsrc/usbip_host_common.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
> index 01599cb2fa7b..94762bc282eb 100644
> --- a/tools/usb/usbip/libsrc/usbip_host_common.c
> +++ b/tools/usb/usbip/libsrc/usbip_host_common.c
> @@ -71,6 +71,8 @@ struct usbip_exported_device *usbip_exported_device_new(
>   	int i;
>   
>   	edev = calloc(1, sizeof(struct usbip_exported_device));
> +	if (!edev)
> +		goto err;
>   
>   	edev->sudev =
>   		udev_device_new_from_syspath(udev_context, sdevpath);
> @@ -107,7 +109,7 @@ struct usbip_exported_device *usbip_exported_device_new(
>   
>   	return edev;
>   err:
> -	if (edev->sudev)
> +	if (edev && edev->sudev)
>   		udev_device_unref(edev->sudev);
>   	if (edev)
>   		free(edev);

thanks,
-- Shuah

      reply	other threads:[~2026-09-22 10:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  6:06 longlong yan
2026-09-22 10:04 ` Shuah Khan [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=b37401c1-b6db-4746-9f6a-af25e9f30829@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=valentina.manea.m@gmail.com \
    --cc=yanlonglong@kylinos.cn \
    /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®