Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5220434pxb; Wed, 26 Jan 2022 07:19:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJww7qj/pNibfSzWOv3r1qsDy/uT1yGG9ZZFQ4eiJOSt7vtA3T4UNFX8DkMmcqOjeclFx76O X-Received: by 2002:a17:907:2d0c:: with SMTP id gs12mr6387495ejc.100.1643210390253; Wed, 26 Jan 2022 07:19:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643210390; cv=none; d=google.com; s=arc-20160816; b=n22iGKDJnHyZhbgQdwRHJoSGEGRsqxI0LUBnruCXyxdPDBC6hXo439/f8cy6LA9OsX vhdO18T9qpLp5iyNigmxoNykovsY6O4OFBN0SXSEIs1h0+gCvvsK+qGyMz5D5l8B9Dle cPfZgN8Lcvj1NPuIz9RPxB0m7PSWmoIiVaaw9V6518R97Em9Sw0HPim99Jf3Qgk+fRS9 BOAYq3TO2PXym3MUg2ph7yMCP7kdBqPXyVEl/N1rHTTwPCabea5thmVVkZJf8s6rvioK A/K1oapWgQNgxK8ZogzGsFFUmywj+P9yLJKWVZ1k6+FdPSxc5eGNoytSG4XgRbvCqCrF guow== 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=IgRdGV/sODqk9GGBA4Td1GoejFpKxVBbsf8keZ9d7dc=; b=bSJGv/J6866bRirCKtMnDqvdUQT5qS37zwNkoaRoHaSwePRf26zqHIu0I87uPqkkm7 u0Zml9zy5kKVWQ8u/lNPLmdH+XMaZ/mDbq8jvoiaDj8c0s2ykapYbw6mCMJ64Fc1ByIa OrQwmGH1KbB5Pk0ZW6MMhKHU6WzEq3mhKJrMGZ+5N1AmojlkPROC3zLiIhp2okhz1oeR 4YFS3ZvJFFLSrtljvcHuiTcHa97H0MZupLCy67Lp0UTAh2jwBWD6MzTI2MijN0UhVlgg i96Y2IfsJIdxug6xEHf0GSTxaPPHISmJRgKfIMcKGQQok+4jUpDiLD1Ee1B6C+bwfvmR y6Wg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nc6si8029315ejc.991.2022.01.26.07.19.25; Wed, 26 Jan 2022 07:19:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236012AbiAZBta (ORCPT + 99 others); Tue, 25 Jan 2022 20:49:30 -0500 Received: from smtp25.cstnet.cn ([159.226.251.25]:34322 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236024AbiAZBtR (ORCPT ); Tue, 25 Jan 2022 20:49:17 -0500 Received: from localhost.localdomain (unknown [124.16.138.126]) by APP-05 (Coremail) with SMTP id zQCowACXe0GHqPBho9zoBg--.31642S2; Wed, 26 Jan 2022 09:48:55 +0800 (CST) From: Jiasheng Jiang To: rafael@kernel.org Cc: daniel.lezcano@linaro.org, rui.zhang@intel.com, amitk@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v3] thermal/int340x_thermal: Check for null pointer after calling kmemdup Date: Wed, 26 Jan 2022 09:48:53 +0800 Message-Id: <20220126014853.2915981-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: zQCowACXe0GHqPBho9zoBg--.31642S2 X-Corem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jqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As the potential failure of the allocation, kmemdup() may return NULL pointer. Then the 'bin_attr_data_vault.private' will be NULL pointer but the 'bin_attr_data_vault.size' is not 0. Therefore, it should be better to check the return value of kmemdup() to avoid the wrong size. And since the error handling process is simple, it may not use the 'goto' to simplify the code. Fixes: 0ba13c763aac ("thermal/int340x_thermal: Export GDDV") Signed-off-by: Jiasheng Jiang --- Changelog v1 -> v2 * Change 1. Use out_kfree to simplify the code. v2 -> v3 * Change 1. Revert the code to v1 and refine the commit message. --- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 8502b7d8df89..52ac3ee54309 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -464,6 +464,11 @@ static void int3400_setup_gddv(struct int3400_thermal_priv *priv) priv->data_vault = kmemdup(obj->package.elements[0].buffer.pointer, obj->package.elements[0].buffer.length, GFP_KERNEL); + if (!priv->data_vault) { + kfree(buffer.pointer); + return; + } + bin_attr_data_vault.private = priv->data_vault; bin_attr_data_vault.size = obj->package.elements[0].buffer.length; kfree(buffer.pointer); -- 2.25.1