Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4771022pxb; Tue, 25 Jan 2022 19:08:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKrBReuaqfqHK96j2B09cgajmqWbid0K6qbH1g23uHMbospKx6TRswBJ8cKvfZNYhl6OJc X-Received: by 2002:a17:906:c08c:: with SMTP id f12mr18338976ejz.419.1643166482482; Tue, 25 Jan 2022 19:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643166482; cv=none; d=google.com; s=arc-20160816; b=VIBCrNvq2oUAJ0EDD6MkdVXizfCA0IhXcEULGmoVPDTu9EyESD6RTfWrcWeDyjqNWz +U0iUsC6Xds3qEgu2lmOI+CwjG/ruYiu2h29h1jlYtvXIMhgGGUBGiLWoHgjyE3e/LTD yZEfFYOhrFScfnx/6iSRwZlO+BR1p8f6d/MhcmydCU1Kdr0tj1zeomr6THcxcgyyx+5m KtZ+9jcGekq4A5uKuCmQzgRoK4FxR/R/N5O8IlUCZrWTTT+CSMSUnulefDmAhYiYfVGx ddcRR6tmPYUFdEO4fjwBS373NQfCq2xCr6MRp2yWYl0gV07qdATo7uzSh0+Ym/gBNN8T rY9w== 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=37oLDsr51k3XVENJHyR2l3wKXsdRvCveBrsGiXcmGKU=; b=spUdY9tsK4a3JDnHmUa2guBeqXVU0wSNbqDTApVFNtwY04gb4ZmJCn84dZrxbL+Lp6 db+i/fjM3aE09lJ3B/ss+RtuEIv/xWmNfDAm9PcjwtDAUc0SoskUql9VH0qQlYy+YoKK XDlFYvxm/JX74A32piDNR0iV3cK/d6Q7UrS1rHPj/eUhhveO2zF5/6Nhsprm+x6Q8n5L HJPD7DvQfoXm+sWxeVPLyjCv5gGD1QfuUipZALBlr8MU/x3Qd+5j/JQ8wLXgRWTtK2IN ClPW0n5KzWKU8gO0gZekK55XShUYx8UylSnHS5Q1itlh+E+9t4RwVe7CE9zqLY9EOKux ZuEw== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bl4si11806217ejb.250.2022.01.25.19.07.38; Tue, 25 Jan 2022 19:08:02 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383350AbiAYRki (ORCPT + 99 others); Tue, 25 Jan 2022 12:40:38 -0500 Received: from mail-yb1-f176.google.com ([209.85.219.176]:45826 "EHLO mail-yb1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381711AbiAYRj1 (ORCPT ); Tue, 25 Jan 2022 12:39:27 -0500 Received: by mail-yb1-f176.google.com with SMTP id h14so63810832ybe.12; Tue, 25 Jan 2022 09:39:23 -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=37oLDsr51k3XVENJHyR2l3wKXsdRvCveBrsGiXcmGKU=; b=iWRrhny68w0EEoaLWGQLaMzkc3fznQs1cpBqjXg3/IgZIo0lj0FhljoNdU9zkwBG/G zc3767nDt9dJ4E5kF4c0xVAtlXeC5GxEIwdtZXvZBgaIodQ040jkUPl96MW6f3gHFIJk uSbmtB1Dsgb/U8MEQyo2cun52mDril01PKNEWXFlbtt/DwhSZOk9U7hQaeKKUGugGGE2 kjnnTJ4/SEwhNeD5kuBxVSpwtceIXUvHLGT7Ro0Vy4KQnKqpzIT1i4MxqULPfvue/LIR HK4FdSpGnTmqMpWWT5WAK6l6AY3hncoPgLisgxL2T51KXwE/DWmrOGAhJt4ksBQ1CE+R N7zg== X-Gm-Message-State: AOAM532tYQ6Cvykvvr7dKYS089okpa1rthYetPKq1orED4a6CrmUs3AZ /hrPiu7p74zpO3Fliscvw2wDpMcMYcv0QT3NFyc= X-Received: by 2002:a25:b8f:: with SMTP id 137mr19315933ybl.330.1643132363575; Tue, 25 Jan 2022 09:39:23 -0800 (PST) MIME-Version: 1.0 References: <20220107144405.4081288-1-jiasheng@iscas.ac.cn> In-Reply-To: <20220107144405.4081288-1-jiasheng@iscas.ac.cn> From: "Rafael J. Wysocki" Date: Tue, 25 Jan 2022 18:39:12 +0100 Message-ID: Subject: Re: [PATCH v2] thermal/int340x_thermal: Check for null pointer after calling kmemdup To: Jiasheng Jiang Cc: 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 Fri, Jan 7, 2022 at 3:44 PM Jiasheng Jiang wrote: > > As the possible 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. > > Fixes: 0ba13c763aac ("thermal/int340x_thermal: Export GDDV") > Signed-off-by: Jiasheng Jiang > --- > Changelog > > v1 -> v2 > > * Change 1. Use out_kfree to simplify the code. > --- > .../thermal/intel/int340x_thermal/int3400_thermal.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > index 19926beeb3b7..f869aeb087d3 100644 > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c > @@ -457,17 +457,21 @@ static void int3400_setup_gddv(struct int3400_thermal_priv *priv) > > obj = buffer.pointer; > if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 1 > - || obj->package.elements[0].type != ACPI_TYPE_BUFFER) { > - kfree(buffer.pointer); > - return; > - } > + || obj->package.elements[0].type != ACPI_TYPE_BUFFER) > + goto out_kfree; This change isn't strictly necessary. > > priv->data_vault = kmemdup(obj->package.elements[0].buffer.pointer, > obj->package.elements[0].buffer.length, > GFP_KERNEL); > + if (!priv->data_vault) > + goto out_kfree; > + > bin_attr_data_vault.private = priv->data_vault; > bin_attr_data_vault.size = obj->package.elements[0].buffer.length; > kfree(buffer.pointer); > + > +out_kfree: > + kfree(buffer.pointer); On success, this would be the second kfree() for the same pointer in a row, which would be a bug. > } > > static int int3400_thermal_probe(struct platform_device *pdev) > --