Received: by 2002:a05:6512:2355:0:0:0:0 with SMTP id p21csp210951lfu; Wed, 30 Mar 2022 21:08:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGVzmz8IYuZOd7J9CxeITEkjEDOEs0O9+iifRyi4V2tqQp2e06r+qSW7dFdgmbk5kljwPp X-Received: by 2002:a17:90b:4a47:b0:1c6:42c6:fef2 with SMTP id lb7-20020a17090b4a4700b001c642c6fef2mr3677285pjb.147.1648699604401; Wed, 30 Mar 2022 21:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648699604; cv=none; d=google.com; s=arc-20160816; b=0ShsTkphHspZ8VxCH9c4NWMgrq1gB4B9qjZlHPXPzCKiNIoJVmmmdghqX9bG59Z6Sw 7JEk/pdXzq5xi+5t98q75/r206LmZChs4g+OSc+hUsRAN4IvPbdGdgmUcyuOmO3Jp7Aj MyNcCRWZrDyNUPoLcyFM6Rt7NSsVnqDy3b4lWO9AHHqpnp5v8kmPwJ7BDF0KDjZwQ0+V hAx0LSxmt0acBOWS4cD9R9YmKnSJjkKPqb81r39O/cjSTGlz8MTrVOkWZYctLTY20B4H 1xqd3T6mLRyU25+KGOSOLVOLSNZ5Z9YQf/7iuCRXW5LsifcgSHgd33HPcUYhpsxOe2Tr OSTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Me/9rcjGJMZep/aCSTGrlz2khUtntlwuVOD8JstO9ic=; b=PkUzo7KfUDHdFjkfKDR8DD/F+plbzj60wcMRlr5GTnZ8sQ3p55sGWrgWasyR8tdx4L DtzPzfoHzHMlQQ98S+TpFNhad0wbn+jd4M/WTmWjXgsHSDBmoyLYvowc2YMenOUihvVQ zLINvJopV1S9SMGaboYnnzvSTKJPB2TxdKZLbn+1loQsYa0qjPV4XHXA3KAZVxVBtjyh OLBRfSaYUOv/RNZjir38Br0C6Rp5iIdhWIDP852b6p5CVjnkGuXdrXM8aZ7BASnuy29d 5CE0SM/p3wdBHVP3OTwkPbqknZAkMidJhM7ltGLCiXmG6Y87FJQhpOYP2/rsvW13XPEA HogA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OmOYMWUo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j13-20020a170903024d00b0015646baef96si3553684plh.594.2022.03.30.21.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 21:06:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OmOYMWUo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B204F16592; Wed, 30 Mar 2022 20:13:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239075AbiC2P6w (ORCPT + 99 others); Tue, 29 Mar 2022 11:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239071AbiC2P6t (ORCPT ); Tue, 29 Mar 2022 11:58:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50B1A4D24E for ; Tue, 29 Mar 2022 08:57:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1396612CA for ; Tue, 29 Mar 2022 15:57:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB7B1C340ED; Tue, 29 Mar 2022 15:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1648569426; bh=3Xtfj0qdi5cXHLbJKQrGPNIsGSjLL6x0WLhsq+/v46Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OmOYMWUoCDRUBDheu6cIabeycMxE8ZjS8OWKaCZ7bUP1WyIBshy8ru93pCcunhuC2 APv+6B7Qgwnhfkynl8IKjhSimJFM9FiM7N4c7PJ/7y3kw2WpjPvbnwSDZ0RQUmzJMI UG1jPO9nUogrIaJchgZqXVixvvOwiGlDU7zv7dXw= Date: Tue, 29 Mar 2022 17:57:03 +0200 From: Greg KH To: xkernel.wang@foxmail.com Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: r8188eu: check the return value of kzalloc() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Fri, Mar 25, 2022 at 02:53:30PM +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 check the return > of it to prevent potential wrong memory access. > > Signed-off-by: Xiaoke Wang > --- > drivers/staging/r8188eu/core/rtw_p2p.c | 2 ++ > drivers/staging/r8188eu/core/rtw_xmit.c | 6 ++++++ > 2 files changed, 8 insertions(+) > > diff --git a/drivers/staging/r8188eu/core/rtw_p2p.c b/drivers/staging/r8188eu/core/rtw_p2p.c > index e2b6cf2..503c4a5 100644 > --- a/drivers/staging/r8188eu/core/rtw_p2p.c > +++ b/drivers/staging/r8188eu/core/rtw_p2p.c > @@ -35,6 +35,8 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf) > DBG_88E("%s\n", __func__); > > pdata_attr = kzalloc(MAX_P2P_IE_LEN, GFP_KERNEL); > + if (!pdata_attr) > + return 0; 0 is not an error. Please propagate this error backwards properly. > > pstart = pdata_attr; > pcur = pdata_attr; > diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c > index 46fe62c..1696272 100644 > --- a/drivers/staging/r8188eu/core/rtw_xmit.c > +++ b/drivers/staging/r8188eu/core/rtw_xmit.c > @@ -180,6 +180,10 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter) > pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf; > > rtw_alloc_hwxmits(padapter); > + if (!pxmitpriv->hwxmits) { > + res = _FAIL; > + goto exit; > + } You just leaked memory resources :( How did you test this? > rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry); > > for (i = 0; i < 4; i++) > @@ -1524,6 +1528,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; You have to return an error, you can not keep going as if all is well. Please always be VERY careful with these types of fixes. Especially if you have not tested them. thanks, greg k-h