From patchwork Mon Dec 19 02:18:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li zeming X-Patchwork-Id: 34369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2153308wrn; Sun, 18 Dec 2022 18:21:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXsRMf7AgJe8iDzYgNoMt9QT0VfcTm4gfFuGPQF8M2s4tOSKQQN+9SJbe+rnCi0hX6gkApiI X-Received: by 2002:a05:6a21:3393:b0:ab:fb31:be13 with SMTP id yy19-20020a056a21339300b000abfb31be13mr10727551pzb.37.1671416470524; Sun, 18 Dec 2022 18:21:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671416470; cv=none; d=google.com; s=arc-20160816; b=YJvv2jjc/xv/wrjW+GztqkB9fEW7dD6WAV1n/cPzUkVh7qgOmGgb0PeyssVJ2bCKWq SpgurkxMP8CUo7Zr5UMTii6w0jD0mYbgbcZ68fKFfxWv79zUuxtfLkdlHdt1lopYnrnu eJW1sjlGAKhcJXtxM6fqEs+lCxC0rCBXpu1iDUABSPtLb8FlIvRXw9+X9d4oNxmjddx7 qn18/NbPxuXuEsUYOmGlcOufsl4BN3gomAhBM1VcurHQ6iSnyC/LE+PL9f/3GDjYTyne PAyj105NA4NV/38W7xumWh2Ub7M5800SQpQC+CXOhNuyCZyUlp3RgKtO5J5wemYBMncM qtDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=pE5GBQ+axLPs7S80kdVVtcIrNpykR22ycA9DkviEheQ=; b=vwbiTthTSX6QQkptNiZPRx7N5lCpc/tDsb03TJmKiwxw3PojQ0qdng6d3OPHQwCncp ZLMqJR/ja3rK3Q6GAlJeQakErojzk6cTDMBbUhH+YkmE5F8liTUF5sw+NiXbQ90FwBVS +/6KOHkYeMgmyXI8P7aAbqSEYpzbwsrAh4tvWHqd7X97S+oEZcMdaVPp2TBPdSN0dOBx bscvaYZZUuvGJxJZ/tGewbsV57v/DHxV82pAKqDIc33v3qkWiEvACrg8iVBjY8s2Q+P0 J17V12NPYyXS6esoE3BFgN6smHkKgJZThS3h5yfWMmhmG5yvZXsxFb4KxGNyl3txFpcR zPuA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a63d809000000b004781e385185si8947771pgh.548.2022.12.18.18.20.57; Sun, 18 Dec 2022 18:21:10 -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 S230481AbiLSCSe (ORCPT + 99 others); Sun, 18 Dec 2022 21:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbiLSCSa (ORCPT ); Sun, 18 Dec 2022 21:18:30 -0500 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6BC47636B for ; Sun, 18 Dec 2022 18:18:29 -0800 (PST) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id B3FFF1E80D6D; Mon, 19 Dec 2022 10:13:31 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id agkulhGKmcTu; Mon, 19 Dec 2022 10:13:29 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id ED2C01E80D32; Mon, 19 Dec 2022 10:13:28 +0800 (CST) From: Li zeming To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu, gregkh@linuxfoundation.org Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Li zeming Subject: [PATCH] boot: simple_alloc: check after increasing memory allocation Date: Mon, 19 Dec 2022 10:18:16 +0800 Message-Id: <20221219021816.3012-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752607196997129479?= X-GMAIL-MSGID: =?utf-8?q?1752607196997129479?= The pointer new adds judgment and should help with program robustness. Signed-off-by: Li zeming --- arch/powerpc/boot/simple_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/boot/simple_alloc.c b/arch/powerpc/boot/simple_alloc.c index 267d6524caac..db9aaa5face3 100644 --- a/arch/powerpc/boot/simple_alloc.c +++ b/arch/powerpc/boot/simple_alloc.c @@ -112,7 +112,9 @@ static void *simple_realloc(void *ptr, unsigned long size) return ptr; new = simple_malloc(size); - memcpy(new, ptr, p->size); + if (new) + memcpy(new, ptr, p->size); + simple_free(ptr); return new; }