Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp423482iob; Tue, 3 May 2022 01:02:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSo7wP6pte7o03sOdQQBMx5/J7AP/gnucTw4Mw2tTUH8//OBxEFwwY8A+aZtOBh0FC0vH4 X-Received: by 2002:a17:90b:1646:b0:1dc:3366:b87e with SMTP id il6-20020a17090b164600b001dc3366b87emr3341528pjb.211.1651564938022; Tue, 03 May 2022 01:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651564938; cv=none; d=google.com; s=arc-20160816; b=YW5XL75yokxG7NoAynBFbA8cFME5WRfbZYaq+iQ5pn3rpwYOusmDdkhcc33Lo5xylK vjU657X1uGRi36j2MHGbJG8adDN5du28JpfYg8rmS2O5m8dpdesoFqIzfMlLv0zd7VQQ OAiLM/VhbvzFFHBheips7jFdtX0aD1mV+BjLZDBI562uevyYjVJVzZHldjkaJL3dbCCK 3wy+ebH4jVyhlMFivVl+cwjz8y6dwHXx4jsoJDvhckwUIjz4G6JW7ftPLLsOhXXdNC2J KJ850LQrlDEevqiseXcpGsc6LKVMK6aSt5pYSxdyOJYdPDV7JUTY6BqIXolazUWRUUI6 N/jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=oUaodAKKzaMb16rqoWXpzBhdgmoWN97EOwM09s8vnU8=; b=OP+i7iRNn4VQtT/+VbF2e/yH2z7hB8KcWyyXujmRIzexAtKRWRk7XJmaFJxjXi5c/0 /znFOM3zsHwBFWMRt4LeUB1qovdiBqw5T1ouwsu9Px0qytOyWH0JMGH+6/J21qdvIOTI bmO+EiBnRQk1I+Q1u3iH4U1aLbvMzkbLBLy4EBHSKQFWz9N0DbM4Op2Rp1igw64AoLKX jHuUCqAc2C9b9A2ooIrXGNbf7KRw23Xs6l1+Bd/b6YyebGZZL+xFVfQ5DQO+6JNaqdV5 EjFi5RLqe+tLjZ2hSUo73BJ5EIx/NizJifp2H+fo9+5CdC8m5/iRLTtU8+B5vk55mX/k Lt4A== 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 j1-20020a056a00174100b0050ad23a8d0esi17206592pfc.113.2022.05.03.01.02.01; Tue, 03 May 2022 01:02:17 -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 S231513AbiECHM3 (ORCPT + 99 others); Tue, 3 May 2022 03:12:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230427AbiECHMX (ORCPT ); Tue, 3 May 2022 03:12:23 -0400 Received: from relay4.hostedemail.com (relay4.hostedemail.com [64.99.140.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AEDC2F388 for ; Tue, 3 May 2022 00:08:49 -0700 (PDT) Received: from omf01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id B9CC7121F1B; Tue, 3 May 2022 07:08:48 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf01.hostedemail.com (Postfix) with ESMTPA id 8799E6000C; Tue, 3 May 2022 07:08:47 +0000 (UTC) Message-ID: Subject: Re: [PATCH 12/12] staging: r8188eu: check the return of kzalloc() From: Joe Perches To: xkernel.wang@foxmail.com, Larry.Finger@lwfinger.net, phil@philpotter.co.uk, gregkh@linuxfoundation.org Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Date: Tue, 03 May 2022 00:08:46 -0700 In-Reply-To: References: Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.4-1ubuntu2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Stat-Signature: ojcbzps174iwotm4ttmiixjy5siz9zhh X-Rspamd-Server: rspamout08 X-Rspamd-Queue-Id: 8799E6000C X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX19WfupWeU9aLuhwiAuAjGXwG8kD2eH7z/Y= X-HE-Tag: 1651561727-358919 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 On Tue, 2022-05-03 at 15:02 +0800, xkernel.wang@foxmail.com wrote: > From: Xiaoke Wang > > kzalloc() is a memory allocation function which can return NULL when > some internal memory errors happen. So it is better to handle the return > of it to prevent potential wrong memory access. > > Besides, to propagate the error to the caller, the type of > rtw_alloc_hwxmits() is changed to `int` and another check is added to > its caller. > Then if kzalloc() fails, the caller will properly jump to the > corresponding error hanlding code. It'd be better to use the typical error returns > diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c [] > @@ -176,7 +176,9 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) > ? > ? pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf; > ? > - rtw_alloc_hwxmits(padapter); > + res = rtw_alloc_hwxmits(padapter); > + if (res == _FAIL) > + goto free_xmit_extbuf; if (res) goto free_xmit_extbuf; [] > -void rtw_alloc_hwxmits(struct adapter *padapter) > +int rtw_alloc_hwxmits(struct adapter *padapter) > ?{ > ? struct hw_xmit *hwxmits; > ? struct xmit_priv *pxmitpriv = &padapter->xmitpriv; > @@ -1495,6 +1497,8 @@ void rtw_alloc_hwxmits(struct adapter *padapter) > ? pxmitpriv->hwxmit_entry = HWXMIT_ENTRY; > ? > ? pxmitpriv->hwxmits = kzalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry, GFP_KERNEL); > + if (!pxmitpriv->hwxmits) return -ENOMEM;