Thread (26 messages) 26 messages, 5 authors, 2025-08-19

Re: [PATCH 1/6] can: esd_usb: Fix possible calls to kfree() with NULL

From: David Laight <hidden>
Date: 2025-08-17 15:02:03
Also in: linux-can

On Fri, 15 Aug 2025 14:57:44 +0000
Stefan Mätje [off-list ref] wrote:
Am Dienstag, dem 12.08.2025 um 13:33 +0100 schrieb Vadim Fedorenko:
quoted
On 11/08/2025 22:06, Stefan Mätje wrote:  
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help