The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Xiaoke Wang <xkernel.wang@foxmail.com>
To: crope@iki.fi, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xiaoke Wang <xkernel.wang@foxmail.com>
Subject: [PATCH] media: usb: dvb-usb-v2: check the return value of kstrdup()
Date: Mon, 13 Dec 2021 15:48:33 +0800	[thread overview]
Message-ID: <tencent_07FF16C8253370EE140700057438B052FD06@qq.com> (raw)

Note: Compare with the last email, this one is using my full name.
kstrdup() returns NULL if some internal memory errors happen, it is
better to check the return value of it. Since the return type of
dvb_usbv2_disconnect() is void, so only raise the error info.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index f1c79f3..a43a310 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -1009,6 +1009,9 @@ void dvb_usbv2_disconnect(struct usb_interface *intf)
 	const char *devname = kstrdup(dev_name(&d->udev->dev), GFP_KERNEL);
 	const char *drvname = d->name;
 
+	if (!devname)
+		dev_err(&d->udev->dev, "%s: kstrdup() failed\n", KBUILD_MODNAME);
+
 	dev_dbg(&d->udev->dev, "%s: bInterfaceNumber=%d\n", __func__,
 			intf->cur_altsetting->desc.bInterfaceNumber);
 
@@ -1023,9 +1026,14 @@ void dvb_usbv2_disconnect(struct usb_interface *intf)
 	kfree(d->priv);
 	kfree(d);
 
-	pr_info("%s: '%s:%s' successfully deinitialized and disconnected\n",
-		KBUILD_MODNAME, drvname, devname);
-	kfree(devname);
+	if (devname) {
+		pr_info("%s: '%s:%s' successfully deinitialized and disconnected\n",
+			KBUILD_MODNAME, drvname, devname);
+		kfree(devname);
+	} else {
+		pr_info("%s: '%s:UNKNOWN' successfully deinitialized and disconnected\n",
+			KBUILD_MODNAME, drvname);
+	}
 }
 EXPORT_SYMBOL(dvb_usbv2_disconnect);
 
-- 

             reply	other threads:[~2021-12-13  7:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13  7:48 Xiaoke Wang [this message]
2021-12-14 15:03 ` [PATCH] media: usb: dvb-usb-v2: check the return value of kstrdup() Mauro Carvalho Chehab
2021-12-14 15:51   ` Xiaoke Wang
  -- strict thread matches above, loose matches on Subject: below --
2021-12-12 14:52 xkernel

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=tencent_07FF16C8253370EE140700057438B052FD06@qq.com \
    --to=xkernel.wang@foxmail.com \
    --cc=crope@iki.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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