Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp4938069rwn; Mon, 12 Sep 2022 01:28:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR6/SuPsn/5C9tD90IxQwrYwoOOY478cIL6cVRqoSX3Nk0ARpEaUoT51gt27xs+p+60m2ZaR X-Received: by 2002:a17:90b:4a0e:b0:202:a7bf:9dd6 with SMTP id kk14-20020a17090b4a0e00b00202a7bf9dd6mr11375948pjb.145.1662971303635; Mon, 12 Sep 2022 01:28:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662971303; cv=none; d=google.com; s=arc-20160816; b=twX45MceKXQNlLoAnepWswsKNSYo75N/iNTGzqrwTwgedLllc7s7ZoEYFlrrRTfQVv IsvGRYI7XiReRQFejybqq1lRQeKP6TuPvRjceEdrVHHS2fU9vkkOEVUGk7QiVlnsMTJP 8iHP7WWIhyJ3JZnOi6ROwRrt+sebAfc7WhAg5t6ORoSQf9c84eeyoE6lEQtuTWKi7Q0t gYqIzNdKS5QMLFD+MTTegkBn8Fh7JMS7JHQxSETHUJkcMEcyFi94UQjunzZV1BZtYm9T ApoRrefilM3QstkDXVXUTuYSFcPf7s5DZvcirn0yMmIiz4Y3Aa/ReZvjz063gfxsqBVd AwOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Bbz2ccr19LWSYsZtrGQBUu/jGk7HGTjAUOXzmEdkFpU=; b=n9RyCc7vCuIkvQS72g+sPREB9dzMD8/Ck2uudyts4IUHJLRafOzJHIgdI0Ub389md1 qJX4oHal139fFr69bQEXJjiWnZFgmc69JzTzuJsqQxqDSIwaU+T88YDrLn9T5FZaOQIs NdhJDR26HyJlLMdq/F9OQTt4NMDdqwJShwx7bXEAFfOfFHSooIx0YHaHXfGecldbzTwP EvTSp3rE8V00A8Lx7Pa1wIvqS/OAhS0OY4TrDTNsDULoS8ekSa5FxtsiNOuqHeofbLY5 rHeBDPwtBYVTINuTH0r+Ry6oOPwC+c5TKRzk0x7DIiqdbXic88LXQdMxYpbU4cKPutt7 y9Xg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 70-20020a17090a0fcc00b001fe0af5ee6dsi8177825pjz.96.2022.09.12.01.28.09; Mon, 12 Sep 2022 01:28:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229926AbiILHfy (ORCPT + 99 others); Mon, 12 Sep 2022 03:35:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbiILHfv (ORCPT ); Mon, 12 Sep 2022 03:35:51 -0400 Received: from viti.kaiser.cx (viti.kaiser.cx [IPv6:2a01:238:43fe:e600:cd0c:bd4a:7a3:8e9f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF2CE2AC63 for ; Mon, 12 Sep 2022 00:35:49 -0700 (PDT) Received: from martin by viti.kaiser.cx with local (Exim 4.89) (envelope-from ) id 1oXdym-0006OW-40; Mon, 12 Sep 2022 09:35:40 +0200 Date: Mon, 12 Sep 2022 09:35:40 +0200 From: Martin Kaiser To: xkernel.wang@foxmail.com Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk, gregkh@linuxfoundation.org, philipp.g.hortmann@gmail.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5] staging: r8188eu: add kfree() on an error path of rtw_xmit_resource_alloc() Message-ID: <20220912073540.l7z56kgjde47r3pr@viti.kaiser.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: Martin Kaiser X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thus wrote xkernel.wang@foxmail.com (xkernel.wang@foxmail.com): > From: Xiaoke Wang > In rtw_xmit_resource_alloc(), if usb_alloc_urb() fails, then the memory > `pxmitbuf->pallocated_buf` which is allocated by kzalloc() is not properly > released before returning. > So this patch adds kfree() on the above error path to release it in time. > Tested-by: Philipp Hortmann # Edimax N150 > Signed-off-by: Xiaoke Wang > --- > ChangeLog: > v1->v2 update the description. > v2->v3 rebase. > v3->v4 update the description. > v4->v5 rebase and update the corresponding subject and description. > Note that the original function name was changed, so the subject of this > patch is updated from "[PATCH v4] staging: r8188eu: fix potential memory > leak in rtw_os_xmit_resource_alloc()" to "[PATCH v5] staging: r8188eu: add > kfree() on an error path of rtw_xmit_resource_alloc()". > In addition, thanks to Philipp Hortmann for his testing and advice. > drivers/staging/r8188eu/core/rtw_xmit.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c > index 67f9c05..9c39d08 100644 > --- a/drivers/staging/r8188eu/core/rtw_xmit.c > +++ b/drivers/staging/r8188eu/core/rtw_xmit.c > @@ -44,8 +44,10 @@ static int rtw_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *px > pxmitbuf->dma_transfer_addr = 0; > pxmitbuf->pxmit_urb = usb_alloc_urb(0, GFP_KERNEL); > - if (!pxmitbuf->pxmit_urb) > + if (!pxmitbuf->pxmit_urb) { > + kfree(pxmitbuf->pallocated_buf); > return _FAIL; > + } > return _SUCCESS; > } > -- Reviewed-by: Martin Kaiser