Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6144416rwb; Sun, 11 Dec 2022 20:04:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6kVik6yJJkVshNQe69S2RTbEH2aai6PfuyfDvf7y5q36fAO0LKHBhOo5bPHpzkKLH2QPuh X-Received: by 2002:a17:906:141a:b0:7c1:4e5d:d8a0 with SMTP id p26-20020a170906141a00b007c14e5dd8a0mr6664545ejc.76.1670817886532; Sun, 11 Dec 2022 20:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670817886; cv=none; d=google.com; s=arc-20160816; b=Zg7+nALsxlhpXPeZr9bIUMw8OQbPNSllH6A9J6x0rCJBaB9w8FEHO4veEzxUMaM/HR Dm+JfQfon6MA9fV+2bmxfbHGFyGuXQV5LBu+ezuXsXnJTRw1F9WUGM7XLiiyY8OaP8VU glaf1F9IfbzKA6/XOIw0GIHU4zDF96D6BJ7AV8F9UpuWWfOHZKZSFYd7DlkoL3/vbXkH V1Bj9PqxjvKBRW3I1VBJqMRxFqWqukrOrNLxmiPgp/Yy0Po0DYP8abPVxZyk4TmpwHeh kWH8NyXve/GfelEEJQKl5RAj8Qb7i1OpDPLP67VyeKA256F4s3bwKfAnnxxgaa+9k1JB sRvg== 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=qepLLP235MGHUhlSV+/6uOUwLJ3ipRFIzR+hUsfJe9U=; b=wyBDFHwN2pA67EiYYsJgy/6NeTESkD3Adv541tFnqQ/5wYFwqLUvUjjuin7s/HKtTW 2w1yNchNElVeaclVIFPAMr0IdXjFVNsTEitYtQUA/XmQyBRm2xR0eX0RbQs2+J6dsPxi 93aFiq9Cj5wavBS8vDzx3PwGFhPo2xDuVECC2tx8IJ97MSmh/t4ZB3EMNQRJB++gI4h9 AnuVcwyPCfRkvS7QuyLug5zEiAqEyvGBdR6/Qmr5CkKKIUNTODZmepCasxXDBMvnGSpd jSCgNWoPs5e7PWXVLI8nEv7c3bAKis+C7PBRXvHT0W6dCdQFRt0KJHF5BD3HKK7FK8cy Qe8Q== 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 gs14-20020a1709072d0e00b007ae2368c8a8si5138117ejc.109.2022.12.11.20.04.28; Sun, 11 Dec 2022 20:04:46 -0800 (PST) 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 S230506AbiLLDj3 (ORCPT + 75 others); Sun, 11 Dec 2022 22:39:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbiLLDj1 (ORCPT ); Sun, 11 Dec 2022 22:39:27 -0500 Received: from cstnet.cn (smtp23.cstnet.cn [159.226.251.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E1CF9CE1B for ; Sun, 11 Dec 2022 19:39:24 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-03 (Coremail) with SMTP id rQCowAD3_3tpopZjsDpIBg--.32227S2; Mon, 12 Dec 2022 11:39:21 +0800 (CST) From: Jiasheng Jiang To: srinivas.kandagatla@linaro.org Cc: linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] nvmem: brcm_nvram: Add check for kzalloc Date: Mon, 12 Dec 2022 11:39:15 +0800 Message-Id: <20221212033915.12674-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: rQCowAD3_3tpopZjsDpIBg--.32227S2 X-Coremail-Antispam: 1UD129KBjvdXoW7Gw1UJFWkWFWrtry7tr1rtFb_yoW3XrX_CF W8urn5Ga4Y9ryIyr1jgw1xZryYy3Z8ZF1qvr1aq3y3Jry3Wr93JrWvvan3A347Zr45KFn3 XrWUAFZ8Ga48WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbckFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr 0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8 GwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r 1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij 64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr 0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF 0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU0NtcUUUUU= X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS 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 Add the check for the return value of kzalloc in order to avoid NULL pointer dereference. Fixes: 6e977eaa8280 ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells") Signed-off-by: Jiasheng Jiang --- drivers/nvmem/brcm_nvram.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c index 4441daa20965..7bd65fc2942e 100644 --- a/drivers/nvmem/brcm_nvram.c +++ b/drivers/nvmem/brcm_nvram.c @@ -97,6 +97,9 @@ static int brcm_nvram_parse(struct brcm_nvram *priv) len = le32_to_cpu(header.len); data = kzalloc(len, GFP_KERNEL); + if (!data) + return -ENOMEM; + memcpy_fromio(data, priv->base, len); data[len - 1] = '\0'; -- 2.25.1