From patchwork Thu Nov 14 08:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhangjiao2 X-Patchwork-Id: 13874720 Received: from cmccmta2.chinamobile.com (cmccmta6.chinamobile.com [111.22.67.139]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66B85E573; Thu, 14 Nov 2024 08:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.22.67.139 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731573648; cv=none; b=LKHvJGW1Y2c0kIwBnc84PxRQotc3JLHwSz8dSowlHrgsJdoF+zld7RFdOyDtqoCkZbRGg9ixeHsE/LcS3+cEcE1SZH/m1p19POYFmxYlc2iXpnZTSXk2YpEIuzgdERq4OnGbzJ5GdKqEpivElapYGwJrGaMCnVOCmTwEvUlPf8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731573648; c=relaxed/simple; bh=8Bq6mXfCwSPUt664VOOXNLdd1zHIpAOXfn1bu2to69Q=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=mZfr57jVIfp39Zj5iJzk5/BHNlCXna88eaaaT/k1twPy1o2C6BEba5JQtSOVX8EAMS1WtvzFAcdZZHH96slp9fjgvvmlYvgcyagxx9WDPOSJqfhA1c3g8KP8rnU9Goe98NAfhNY7BvG9sN3YNhtkFTDEV8qfoiPmrJYAzzZmnVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com; spf=pass smtp.mailfrom=cmss.chinamobile.com; arc=none smtp.client-ip=111.22.67.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cmss.chinamobile.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app05-12005 (RichMail) with SMTP id 2ee56735b788efa-20f10; Thu, 14 Nov 2024 16:40:41 +0800 (CST) X-RM-TRANSID: 2ee56735b788efa-20f10 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from localhost.localdomain (unknown[223.108.79.101]) by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee16735b787100-b6a86; Thu, 14 Nov 2024 16:40:41 +0800 (CST) X-RM-TRANSID: 2ee16735b787100-b6a86 From: zhangjiao2 To: daniel.lezcano@linaro.org Cc: rafael@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, zhang jiao Subject: [PATCH v2] tools/thermal: Fix common realloc mistake Date: Thu, 14 Nov 2024 16:40:39 +0800 Message-Id: <20241114084039.42149-1-zhangjiao2@cmss.chinamobile.com> X-Mailer: git-send-email 2.33.0 Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: zhang jiao If the 'realloc' fails, the thermal zones pointer is set to NULL. This makes all thermal zones references which were previously successfully initialized to be lost. Signed-off-by: zhang jiao --- v1->v2: Modify commit info and use right type. tools/thermal/thermometer/thermometer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c index 1a87a0a77f9f..6df6ffdc571a 100644 --- a/tools/thermal/thermometer/thermometer.c +++ b/tools/thermal/thermometer/thermometer.c @@ -259,6 +259,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling, { int fd; char tz_path[PATH_MAX]; + struct tz *tz; sprintf(tz_path, CLASS_THERMAL"/%s/temp", path); @@ -268,12 +269,13 @@ static int thermometer_add_tz(const char *path, const char *name, int polling, return -1; } - thermometer->tz = realloc(thermometer->tz, + tz = realloc(thermometer->tz, sizeof(*thermometer->tz) * (thermometer->nr_tz + 1)); - if (!thermometer->tz) { + if (!tz) { ERROR("Failed to allocate thermometer->tz\n"); return -1; } + thermometer->tz = tz; thermometer->tz[thermometer->nr_tz].fd_temp = fd; thermometer->tz[thermometer->nr_tz].name = strdup(name);