Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp197925iob; Tue, 17 May 2022 23:34:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzACfKKQkVXWUNvT6VxcBaAZxJh4R9L95rZJIDWPkR/U2EPhrEu2xbgHKQnxPMrkiTzXhG6 X-Received: by 2002:a05:6a00:170d:b0:512:ebab:3b25 with SMTP id h13-20020a056a00170d00b00512ebab3b25mr23235120pfc.32.1652855685794; Tue, 17 May 2022 23:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652855685; cv=none; d=google.com; s=arc-20160816; b=JOspnue5i89RGlFHh8DacLbQgHuRch3Cx4P5vOCR+KSokuXU0eK5khwknK2PkStJiO /M/2hIwYyF62pYlbxl647m7F+nY4zh6789ADgMaia0XI7iiZ9hblmChEw/BO8Kjh1QWv 8rJzLvZELe7eI/y4Npg7xssurJKHx4hFrd9elCisX7xr/8gs+yjBZNpNbNLs432ULk5J Q5zAJ34VGGnQpql3JIrBIYY6vX6iiI7z1bY89jxTIYoE0SFs5mdd4yeXrgNXHWBlcAVB b3SsnNqmPvRbHM73bUsozz3dDi9jOjqowBoaQFaU2VUdUoAeWU3Y5plzPpIUD8KjeND9 UVvQ== 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 :message-id:date:subject:cc:to:from; bh=vITaXh/Umua2WtjsvrtR/bQv8fUi7kmK8KSVpqzmZfQ=; b=0Yb9esLG6xvV5ysQMcRpdBSCdIDZq9yFQgXxy2mJoT7tS6XXwiSXPtP66AuGRgBfPh vUHJYIa6d5gTA0NoFE63QA8Me3htAn/yxvMKZtimf0GpVwVS8GIc9wtOcPFQMNAx4BNM 1qgCQ4c93Hne43KsJXui1KozFaXLuKNfMgp5r3kZ3KviKf6Ur62FqRWL2wgmt4YnEhHn YFohxTpcSF2LPlHjbek8An9DPYvnhHygVzNx/F/vpZhAkLjRzemoVnFlajnouXZr2vpT D/MHjkmLa4LzdYVeskYcvkOBk7jGJh5lyHzFRCJ7VIFX7plJwKP7LwlZ8b2UpTl0IuvK rfVw== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y4-20020a63ce04000000b003c574b2e2a4si1303062pgf.744.2022.05.17.23.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 23:34:45 -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; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 97666DFF5A; Tue, 17 May 2022 23:30:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbiERGam (ORCPT + 99 others); Wed, 18 May 2022 02:30:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbiERGal (ORCPT ); Wed, 18 May 2022 02:30:41 -0400 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B04172AC3 for ; Tue, 17 May 2022 23:30:38 -0700 (PDT) Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-05 (Coremail) with SMTP id zQCowAA3PZGDkoRi2FJxCA--.25107S2; Wed, 18 May 2022 14:30:29 +0800 (CST) From: Jiasheng Jiang To: dan.carpenter@oracle.com Cc: Larry.Finger@lwfinger.net, phil@philpotter.co.uk, gregkh@linuxfoundation.org, straube.linux@gmail.com, fmdefrancesco@gmail.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v2] staging: r8188eu: add check for kzalloc Date: Wed, 18 May 2022 14:30:24 +0800 Message-Id: <20220518063024.514280-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowAA3PZGDkoRi2FJxCA--.25107S2 X-Coremail-Antispam: 1UD129KBjvJXoWxGrW5Jw1kuw4ftFyUArW3Awb_yoW5Ary7pF s5u34rCFsYvr12kr4DKF1UAry3ua4rGFyUtFyxtwn09FyIyF1UGryYy3WYvr4fZrs29wn8 Kr92g34Uua1DCFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F 4UJVW0owAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0E wIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04 k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY 1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbXdbUUUUUU== X-Originating-IP: [124.16.138.126] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 As kzalloc() may return null pointer, it should be better to check the return value and return error if fails in order to avoid dereference of null pointer. Moreover, the return value of rtw_alloc_hwxmits() should also be dealt with. Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver") Signed-off-by: Jiasheng Jiang --- Changelog v1 -> v2: *Change 1. Make rtw_alloc_hwxmits() return -ENOMEM on failure and zero on success. --- drivers/staging/r8188eu/core/rtw_xmit.c | 11 +++++++++-- drivers/staging/r8188eu/include/rtw_xmit.h | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c index c2a550e7250e..0b3bcfbf22f7 100644 --- a/drivers/staging/r8188eu/core/rtw_xmit.c +++ b/drivers/staging/r8188eu/core/rtw_xmit.c @@ -178,7 +178,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); + res = rtw_alloc_hwxmits(padapter); + if (res) + goto exit; + rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry); for (i = 0; i < 4; i++) @@ -1474,7 +1477,7 @@ s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe) return res; } -void rtw_alloc_hwxmits(struct adapter *padapter) +int rtw_alloc_hwxmits(struct adapter *padapter) { struct hw_xmit *hwxmits; struct xmit_priv *pxmitpriv = &padapter->xmitpriv; @@ -1482,6 +1485,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; hwxmits = pxmitpriv->hwxmits; @@ -1498,6 +1503,8 @@ void rtw_alloc_hwxmits(struct adapter *padapter) hwxmits[3] .sta_queue = &pxmitpriv->bk_pending; } else { } + + return 0; } void rtw_free_hwxmits(struct adapter *padapter) diff --git a/drivers/staging/r8188eu/include/rtw_xmit.h b/drivers/staging/r8188eu/include/rtw_xmit.h index b2df1480d66b..e73632972900 100644 --- a/drivers/staging/r8188eu/include/rtw_xmit.h +++ b/drivers/staging/r8188eu/include/rtw_xmit.h @@ -341,7 +341,7 @@ s32 rtw_txframes_sta_ac_pending(struct adapter *padapter, void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry); s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter); void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv); -void rtw_alloc_hwxmits(struct adapter *padapter); +int rtw_alloc_hwxmits(struct adapter *padapter); void rtw_free_hwxmits(struct adapter *padapter); s32 rtw_xmit(struct adapter *padapter, struct sk_buff **pkt); -- 2.25.1