From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCA6A241CA2 for ; Mon, 29 Dec 2025 15:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767022103; cv=none; b=s1W+ZOUuwLivUsLdj2HKokx2gAljzwr6eYnrytFC1WhYRZJDQNUrsLclS1L96JjWzrszJoppdrmlvf7UpzHA3/xOt8mRbF7FpciyiA2T3SXHY1HodJFuag/e3Ot329O95xWxNUpAZv7Zm8h2qvNOG7/4E86WSOcyqWlmR/Aspao= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767022103; c=relaxed/simple; bh=tO4LiOAYNo6LQjet9t922z8cMhzjhhLB8KJNYrWAzWM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YN0B95tHl81uNH4HUoSBB02PDBVKWY2uR2b0zeliwOg8GPSePvSzoTgriMSwUtMXYuGvhBMIWtom0BdFRPxKYlt1ZKIHzxX4w+Noox2hmUAz1fgnjln0BtJhAuBctPDPmVbmMicaRKuPOfbnqkZid0HS+B6atLVisSfYXu0epo0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JRCDrSpz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JRCDrSpz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B1DEC4CEF7; Mon, 29 Dec 2025 15:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1767022103; bh=tO4LiOAYNo6LQjet9t922z8cMhzjhhLB8KJNYrWAzWM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JRCDrSpz/tVi3DuvHXwGnQ3JThwFtz1zmQmpIGUOmBcdrIXtQYGc5nTeiHR935Pf0 pA+XWQblspIt/OVxFBSghif6zxbxrgb7ElTvZwbP90W+aj/EpUoaisedj1KDyGvQEU O1E3qJ+er2CpAs05XOT6d10z3810AWtyaZqWDlJg= Date: Mon, 29 Dec 2025 16:28:21 +0100 From: Greg KH To: Zilin Guan Cc: dpenkler@gmail.com, matchstick@neverthere.org, mingo@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Jianhao Xu Subject: Re: [PATCH v2] staging: gpib: Fix memory leak in ni_usb_init() Message-ID: <2025122925-navigator-settle-9873@gregkh> References: <20251229152203.475658-1-zilin@seu.edu.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251229152203.475658-1-zilin@seu.edu.cn> On Mon, Dec 29, 2025 at 03:22:03PM +0000, Zilin Guan wrote: > In ni_usb_init(), if ni_usb_setup_init() fails, the function returns > immediately without freeing the allocated memory for writes, leading > to a memory leak. > > Fix this by freeing writes before returning the error code. > > Fixes: 4e127de14fa7 ("staging: gpib: Add National Instruments USB GPIB driver") > Suggested-by: Dave Penkler > Co-developed-by: Jianhao Xu > Signed-off-by: Jianhao Xu > Signed-off-by: Zilin Guan > --- > Changes in v2: > - Use early return to simplify error handling logic. > > drivers/gpib/ni_usb/ni_usb_gpib.c | 8 +++++--- As the code is no longer in staging, that prefix does not need to be ther. > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpib/ni_usb/ni_usb_gpib.c b/drivers/gpib/ni_usb/ni_usb_gpib.c > index 1f8412de9fa3..2352c6817440 100644 > --- a/drivers/gpib/ni_usb/ni_usb_gpib.c > +++ b/drivers/gpib/ni_usb/ni_usb_gpib.c > @@ -1799,10 +1799,12 @@ static int ni_usb_init(struct gpib_board *board) > return -ENOMEM; > > writes_len = ni_usb_setup_init(board, writes); > - if (writes_len) > - retval = ni_usb_write_registers(ni_priv, writes, writes_len, &ibsta); > - else > + if (!writes_len) { > + kfree(writes); > return -EFAULT; This is not the correct error value, it should only happen if copy to/from user fails. I know it's not the issue here, just noticed this. And why doesn't ni_usb_setup_init() return an error value that should be propagated upward? thanks, greg k-h