Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2131535pxb; Fri, 25 Mar 2022 11:38:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsikphph7PU3YhIACbD7HBIBNqWt7A4It5MZA3CvRKgYwoBTfeGO2xwA3/omVy1BlIgCt/ X-Received: by 2002:a17:90b:33d2:b0:1c6:f3c1:49c3 with SMTP id lk18-20020a17090b33d200b001c6f3c149c3mr14002205pjb.82.1648233505323; Fri, 25 Mar 2022 11:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648233505; cv=none; d=google.com; s=arc-20160816; b=zQ9NvqAHTXENk4nz0UGhuGoCf6VSBm1636jKQCZSrJvSR7S7A8i6sHP46u1f+h9w0S 8Kv6OkjmeMdAcc2Qt3gKExKo79NlgelB5orNnmfLhGPrfEMu101LGvB+WX2KNYYjGAbc hGccKL2rWCuEQcd3tbWVtEX9z673a5yomFbzFDCdJ/yNdmsel6ccOECvE4EMY5UoAOaB M22/78zuEaIJTE8N4gAWQqMuK4m9x0loQkuHNfTxDjhNaGKc6jT1fmWrKAl31fiqUibr WjNg5Sxktl1+Kjeu3ro1sPfUXlca0BpbZH1Eei/cI3uqjFvy7b6qIi0m6K9+O8oXqch0 E43Q== 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:date :subject:cc:to:from:message-id:dkim-signature; bh=DgLAnYgqjoM4AGSmu3Sc6+ngc8WyuI9dDOEV/Xp0GDY=; b=D+sy1eh3FTBdCjjQhmotGislJfe4uXVneO9P825e18EFv9ZG9seQRDtQa32BG/t2Nu R56YjSqZJA3dFr4rFHbav1X50CY27zbNMf9MlSAHtuE98rKKIqp3dja07gurTX9lNvNC 2+UB3JAGHiUytxEu3CKN3ycmlzQV1VYt83jZG1flvVV1gz0WgejPqsr2qKc4ganQQV3y P98MGpVnO+8Ld3W+ExYhS7IyzTo0ePRWapYI5nAbNgen/5nW1mSEllNWYmJUhqwVN7/v Z4CuF3jEIqAdQVGTHQsLJWynCeQ6CoTTB4uCGdBzpz35riVRELiuaILhgFsb3zF39Gu2 wbiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=Y+jcMMOY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bf15-20020a656d0f000000b00381fa9dc403si3307718pgb.679.2022.03.25.11.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:38:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=Y+jcMMOY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 70A9B192580; Fri, 25 Mar 2022 10:56:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243896AbiCYI6B (ORCPT + 99 others); Fri, 25 Mar 2022 04:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbiCYI57 (ORCPT ); Fri, 25 Mar 2022 04:57:59 -0400 Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1998CD321 for ; Fri, 25 Mar 2022 01:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1648198581; bh=DgLAnYgqjoM4AGSmu3Sc6+ngc8WyuI9dDOEV/Xp0GDY=; h=From:To:Cc:Subject:Date; b=Y+jcMMOY3yb/9VPHBubyBshdnPAe+XQmJ1yhT52uEE9Fm7szyoiPl9dMpsu3zDObi tVmA+EHaZcOCuJu/6sEfVmb8i1/G0QxLBpMXY1oygO8Gtp4Bvc16e2x40gTutoGKRz LS70+zv/6EC2zXDXPJYffoKDNwI2gxBhn/yXs+Io= Received: from localhost.localdomain ([218.197.153.188]) by newxmesmtplogicsvrszc11.qq.com (NewEsmtp) with SMTP id E0F8E616; Fri, 25 Mar 2022 16:56:15 +0800 X-QQ-mid: xmsmtpt1648198575tr71poz2m Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9+4HHGI5DBsw11FVsz9FqPSQt4NfwIwKTIa/TEmwAEoWffMfTS9 6mQPgPCzRKkTXdfKK5A/b5bddX6a/8pLe+oGAO6tgN8xJdbouFE/D3ICYynyVFtVVFHTDNmWAwQF 3d9hdo+MzrPNvkGjUyad1+bgEQ0H0jgn/ixA940rReW+kH6V1jRopguw6BmWgummK9Lt5CyEOPOw 3IaqVlgP1qQPvFp7PmAnIChv2ChFb/Od9pcTwkso0KPraMqL0z4LtKDpa4gcS9v0dUryZqJp2OkA G8d/rXhEyMdB16SsECYUzVVpC83NHPttTBiDHME81zpGbNelWWyv6Zgwbh5dQpKWkiBh0T8mzBdr wuNERk2CEoQIc1y3dVlc6nOr6/Hik+t+AZ7mfzuage5O4LfHi7Sf9RQMIZRxkY9SjQ0PxJHIm+oy oQjgOacNfpwwin1hBrtO07yaPtt29oY5aqv+mV4rCGz287ymmR7lL9CyEEnOL1XAJDRtBuFSF0vi qOUiEKSFN5E33hwBRpW+zJR1paR1XHGjRpeEjNfw23j0J38NCA7Db7VoaTqkmJoTAkCcmqVvmXYF uPT/j320DYscqlDTA2KcEXyhLSM0te4+oQGWBst4Ky3uTzN+04+PKWP90Y0bp9QdAyS6LIiMQYsI tGKxoucmdbp3XDfzuG3LQardQLf93pWe13HgnAsuxmQ8FttbZwTRidDNJXCb+L6Ux+0YMY5bDCvG MGFUtDqMCp5VAigOEUy/DNbRXDQyR0tPTv1ZMNJKc0B05wmgTtMMyNTpzBcLUM0OhTzN2wV0W77g u09knU6bm6jK+Eok/mKCDHSmoKMQdNv2fRqm7G9TYP375HfyAN2jV9RV65xPmuP6xZUNee0VHAtf BaCXkhSbH/OpvburTa3CYcc8KqiTOYUmil8aDdpBF5r/WxK6/rtulM3HNDsZiCnOr8Mw+qN9iGqp iRRbtAUcA= From: xkernel.wang@foxmail.com To: andrew@lunn.ch, gregory.clement@bootlin.com, sebastian.hesselbarth@gmail.com Cc: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Xiaoke Wang Subject: [PATCH] ARM: mvebu: check the validation of memory allocation Date: Fri, 25 Mar 2022 16:55:18 +0800 X-OQ-MSGID: <20220325085518.4016-1-xkernel.wang@foxmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 From: Xiaoke Wang kzalloc() and kstrdup() are memory allocation functions which can return NULL when some internal memory errors happen. So it is better to check the return value of them to prevent potential wrong memory access or memory leak. Signed-off-by: Xiaoke Wang --- arch/arm/mach-mvebu/board-v7.c | 8 ++++++++ arch/arm/mach-mvebu/coherency.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c index d2df5ef..86d1f4e 100644 --- a/arch/arm/mach-mvebu/board-v7.c +++ b/arch/arm/mach-mvebu/board-v7.c @@ -128,11 +128,19 @@ static void __init i2c_quirk(void) struct property *new_compat; new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL); + if (!new_compat) + continue; new_compat->name = kstrdup("compatible", GFP_KERNEL); new_compat->length = sizeof("marvell,mv78230-a0-i2c"); new_compat->value = kstrdup("marvell,mv78230-a0-i2c", GFP_KERNEL); + if (!new_compat->name || !new_compat->value) { + kfree(new_compat->name); + kfree(new_compat->value); + kfree(new_compat); + continue; + } of_update_property(np, new_compat); } diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c index 49e3c8d..eb6b349 100644 --- a/arch/arm/mach-mvebu/coherency.c +++ b/arch/arm/mach-mvebu/coherency.c @@ -194,7 +194,13 @@ static void __init armada_375_380_coherency_init(struct device_node *np) struct property *p; p = kzalloc(sizeof(*p), GFP_KERNEL); + if (!p) + continue; p->name = kstrdup("arm,io-coherent", GFP_KERNEL); + if (!p->name) { + kfree(p); + continue; + } of_add_property(cache_dn, p); } } --