Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4347369pxb; Sat, 5 Feb 2022 10:35:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3mp5vxfHR1ZAm5sQpQW71ChAeq0/0MM8uNs5lk86kMLxs6smNNAMzLmgJzufJdoalypSh X-Received: by 2002:a17:902:eb84:: with SMTP id q4mr804153plg.90.1644086100665; Sat, 05 Feb 2022 10:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644086100; cv=none; d=google.com; s=arc-20160816; b=KPF6dez3HmBQ+Z4EQnHpODqxHiblcRxHCS1GpTEUfG8yHRmbaYuwJHauT5nL1l/6wA le4V+5/DAp9gtq8mDDhivyMT+q3SJWPT09fa+UVDXG6vyxBWwxRfC0w1MpJ/qNwoVZ/1 IG71QReWXIVNYY988j3jPw7ThwhQMi9niA3iCYGxBqaDo8qjKrhJuPhfqtIkseWihG+4 WAGrKjPAO8H/X+RmCnJgz9To0hOsrEgfnl0BjtgEZanl6XsMaAApm+d+hu7upzeW02eq eGaLhYZ+eYAlrv1MyjABqYCZ8uLybevlZHQwmuOETq8qzn6VDcL0n+nD1iTcJvdXXnwA t6MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=1KpgwQenVwyvbtZUfE0b3LoE53JfPaVnSYNKALVtwLc=; b=JbgsqTIVj5jEAH42+IAuigwCS626BwuRxwywiJjbZ1Q9LVWELV2+OH0j+zhihh+JOi 0hxPIehHR+dSK19cQr7NXYw99eSnIhQxOurXh+zatcGXkFuksOrQEHfuugEM8qJe8FEI y7OxV2VMG4jm9TuGdfR7R86qShOH2ahUcGIuSLUR2MpLYofnWulwzTYO2xNL5yuxoC7I gLIpdp5A92aaLSvkz4uFAmM0/9IzfMFPhYIdu/I8VF/QUdQJbg6eY58a84v2YlVDOI0u xBb5JVtwD79rq6TOHQq4Afp8u/JWZxK0GZGaZ3iI91IUlaijir+ooY/Q8A6BAAXY0HOW X8xA== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20si4980748pjq.121.2022.02.05.10.34.49; Sat, 05 Feb 2022 10:35:00 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377221AbiBDR6U (ORCPT + 99 others); Fri, 4 Feb 2022 12:58:20 -0500 Received: from mail-yb1-f175.google.com ([209.85.219.175]:36486 "EHLO mail-yb1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377200AbiBDR6T (ORCPT ); Fri, 4 Feb 2022 12:58:19 -0500 Received: by mail-yb1-f175.google.com with SMTP id c6so21050988ybk.3; Fri, 04 Feb 2022 09:58:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1KpgwQenVwyvbtZUfE0b3LoE53JfPaVnSYNKALVtwLc=; b=ooW2cVNhF+vxk4CEQxUCHkKzvc48NDyLNIMwXe4X9eVe1Odb80zmfH7V7XXh1GNzUW TyC1lizVvsP4l7VFILIra9G/e0qV+fU25oBR/7BpKGue9ZtXaIb9RLtPwx+Giwmpa334 l+mQ+cbnK5CovlT4/tXGkANCTCdkTxdRqeQfzNFQXqAoLd9sz1s9nM9j2COA9FQ+6ON/ uPZBWOb5nyiwpaItG4tzq2iNA9ZT+GRwt3K0j0pKwVP+VOLIMF68mm2gaoFdjdLINK5H +a7fuMm8M88DhThiivvjJlYMjsYDmv5pV9HbeSC45thxzSf0K4bZQ7NRh5G5oljdTBQf 0tZg== X-Gm-Message-State: AOAM531EeMK2AFdlLAWvfkR4msj8n3rOAc16FoJI+CWHZYzn1+Wn/pmL Z1qdcnyol9fNtvdDDU1JAjw/xPzNuupcaLQIIjZVr+zG X-Received: by 2002:a81:3744:: with SMTP id e65mr613498ywa.301.1643997498498; Fri, 04 Feb 2022 09:58:18 -0800 (PST) MIME-Version: 1.0 References: <20220126014853.2915981-1-jiasheng@iscas.ac.cn> In-Reply-To: <20220126014853.2915981-1-jiasheng@iscas.ac.cn> From: "Rafael J. Wysocki" Date: Fri, 4 Feb 2022 18:58:07 +0100 Message-ID: Subject: Re: [PATCH v3] thermal/int340x_thermal: Check for null pointer after calling kmemdup To: Jiasheng Jiang Cc: "Rafael J. Wysocki" , Daniel Lezcano , "Zhang, Rui" , Amit Kucheria , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 26, 2022 at 2:49 AM Jiasheng Jiang wrote: > > 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); > -- Applied as 5.18 material with some edits in the subject and changelog, thanks!