From: David Laight <david.laight.linux@gmail.com>
To: "Stefan Mätje" <stefan.maetje@esd.eu>
Cc: "vadim.fedorenko@linux.dev" <vadim.fedorenko@linux.dev>,
"linux-can@vger.kernel.org" <linux-can@vger.kernel.org>,
"mkl@pengutronix.de" <mkl@pengutronix.de>,
Frank Jungclaus <frank.jungclaus@esd.eu>,
"mailhol.vincent@wanadoo.fr" <mailhol.vincent@wanadoo.fr>,
socketcan <socketcan@esd.eu>,
"horms@kernel.org" <horms@kernel.org>,
"socketcan@hartkopp.net" <socketcan@hartkopp.net>,
"olivier@sobrie.be" <olivier@sobrie.be>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH 1/6] can: esd_usb: Fix possible calls to kfree() with NULL
Date: Sun, 17 Aug 2025 16:02:00 +0100 [thread overview]
Message-ID: <20250817160200.76467a18@pumpkin> (raw)
In-Reply-To: <9e30abd4fe42b56158debde0caf71ebac89cc8cb.camel@esd.eu>
On Fri, 15 Aug 2025 14:57:44 +0000
Stefan Mätje <stefan.maetje@esd.eu> wrote:
> Am Dienstag, dem 12.08.2025 um 13:33 +0100 schrieb Vadim Fedorenko:
> > On 11/08/2025 22:06, Stefan Mätje wrote:
> > > In esd_usb_start() kfree() is called with the msg variable even if the
> > > allocation of *msg failed.
> >
> > But kfree() works fine with NULL pointers, have you seen any real issues
> > with this code?
>
> Hello Vadim,
>
> I've not seen real problems with this code. And when I posted the patch I
> knew that kfree() can cope with NULL pointers. But in any case calling a
> *free() function with a NULL pointer sends shivers over my spine and I
> want to avoid to stumble over this again and again.
The only time it is worth the check in the caller is the case where it
is normal for the pointer to be NULL.
But for an error exit it is safer to have one exit path that tidies everything
up rather than lots of them where there is the opportunity to exit via the
wrong one.
David
next prev parent reply other threads:[~2025-08-17 15:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 21:06 [PATCH 0/6] can: esd_usb: Fixes and improvements Stefan Mätje
2025-08-11 21:06 ` [PATCH 1/6] can: esd_usb: Fix possible calls to kfree() with NULL Stefan Mätje
2025-08-12 12:33 ` Vadim Fedorenko
2025-08-15 14:57 ` Stefan Mätje
2025-08-17 15:02 ` David Laight [this message]
2025-08-13 9:20 ` Marc Kleine-Budde
2025-08-15 15:02 ` Stefan Mätje
2025-08-19 16:16 ` Stefan Mätje
2025-08-11 21:06 ` [PATCH 2/6] can: esd_usb: Fix not detecting version reply in probe routine Stefan Mätje
2025-08-13 8:26 ` Marc Kleine-Budde
2025-08-13 11:44 ` Vincent Mailhol
2025-08-19 16:41 ` Stefan Mätje
2025-08-19 16:23 ` Stefan Mätje
2025-08-11 21:06 ` [PATCH 3/6] can: esd_usb: Fix handling of TX context objects Stefan Mätje
2025-08-13 8:14 ` Marc Kleine-Budde
2025-08-15 15:29 ` Stefan Mätje
2025-08-11 21:06 ` [PATCH 4/6] can: esd_usb: Add watermark handling for TX jobs Stefan Mätje
2025-08-13 8:13 ` Marc Kleine-Budde
2025-08-18 9:55 ` Stefan Mätje
2025-08-11 21:06 ` [PATCH 5/6] can: esd_usb: Rework display of error messages Stefan Mätje
2025-08-13 8:12 ` Marc Kleine-Budde
2025-08-14 12:45 ` Marc Kleine-Budde
2025-08-18 12:21 ` Stefan Mätje
2025-08-11 21:06 ` [PATCH 6/6] can: esd_usb: Avoid errors triggered from USB disconnect Stefan Mätje
2025-08-13 8:09 ` Marc Kleine-Budde
2025-08-16 13:11 ` Stefan Mätje
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=20250817160200.76467a18@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=frank.jungclaus@esd.eu \
--cc=horms@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=olivier@sobrie.be \
--cc=socketcan@esd.eu \
--cc=socketcan@hartkopp.net \
--cc=stefan.maetje@esd.eu \
--cc=vadim.fedorenko@linux.dev \
/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