Message ID | 20240221123936.3421462-1-colin.i.king@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-74708-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1007818dyc; Wed, 21 Feb 2024 04:40:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWSQCAnaPy1JjvavbZ/160g4oBf3JJid10356BGQPWJcJ3jPhzALigaLe8+ozz0f8Mr23muGaHOcmbz09zHnD1OQdWviA== X-Google-Smtp-Source: AGHT+IHeYDZztl6NGzLktFniLN+JYfhGrwxmk9fLtQCC/DEFHCd6c6rII/3YAMC0tM/Ck2bEkkG3 X-Received: by 2002:a05:6808:1907:b0:3c0:408f:2098 with SMTP id bf7-20020a056808190700b003c0408f2098mr25845403oib.24.1708519209304; Wed, 21 Feb 2024 04:40:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708519209; cv=pass; d=google.com; s=arc-20160816; b=02ARRd1YnlImSCY0olBs3+UCQfWswQTpQ1ABR/tfhrEOpe5AN2rESvR46jr+vUpzqY TnXb9O3pNWnZWXUQVAMi8q0wRaV1mnpz0lSDe7dPw3SDelq8k2WR7trtSpyDENbuDAeZ H4x1AfEnJy1tFra70xGi14Ki5Mij/G0ZSrDthi3HDXpHgd+D+ZL4+HclkuJFtUWHWf0f DqJ/H16SszS0Pkqt7QseWnyjaPPJFQsj5Nr11XaMBrL65FJVX9XkXk6ip5kHHlLVHXti Vt7Q6sce25S7DwgfHavT90TIcdISCnBcmc4yNsbTO7hiAZ/J+CXsNP87K23TAYDe2QBI lZkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=TVXQ0SykxtzeFN8y51Iqsk4cWHv4fF8waP8HNiw0MEc=; fh=eJJzEMam2lZAWJsYRaje7oJ5v3D8bakGd4H1h0uMu9w=; b=kTmjClqPofTiOxLu72Ag6mu+BiiITJs+2+nR3ej+mJ2sxf2Fhy5cHmlZJGBCzavuQX 9llj5js7lVtJqlubJg7RMTPRnFwOO45bSCO8beK3jh+awMDRSppWPXXBkCrgzr+Kcmdl IjTsVuE7ibJj4yQUw8z9nytc3JfEPu/1pgfU2ueQgYan+ZCq4Gsm3kpN1zpjgkmaN395 yzzJsY+qFDSB6mh5xAhL9mzDbv9wZlr0rMdxpOlV8ieQvVP349X4mI6C0qAGCqLi5gK3 lFjU67hA4pV6lzn9jgJ0Kj7NfxY0+hvHV1Bj1IWaGtz+15QleCQBNYqDUjoUORz4KNbh jJQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="H0fv94/P"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-74708-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74708-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y15-20020ac8708f000000b0042c66991e91si10279933qto.668.2024.02.21.04.40.09 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 04:40:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74708-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="H0fv94/P"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-74708-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74708-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1A0A11C22594 for <ouuuleilei@gmail.com>; Wed, 21 Feb 2024 12:40:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5626569D2A; Wed, 21 Feb 2024 12:39:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H0fv94/P" Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0300669319; Wed, 21 Feb 2024 12:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708519181; cv=none; b=MdHBfA55Uvo4KlLz2rFFYJruKqWKsZqajtBlBzUNye5iUAtydqnP0pECH0+80MgGF/bp17kbZ2a7o+gP+5/K1hsM/IKc/wsEGHUjkegozUvoY9Zg1j8qb6ULr1Ydnc04lWt+3vvINF8HvYHevA15vE29f/i863PsZTNxo+t3Eeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708519181; c=relaxed/simple; bh=Qe/A6k+4smPWDWXCEf215lQP3giMaXGWgCGQgwSs7sM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=nlzK8wc/OvFC9dlTRnaSiQtCh3sWiKC3EqFmDyh66SKBWxMHjsotvcp/TREIdfRQ2QhUE7FMo8nngnqQOWSA9vSPPEov+4CaQCqk0tIlaX4uz15CJ6hXPnYOkbP2WNbO2LAsTfUA3IyXCLZWPYpT9pkS065M5jUyDFJDMzpt3Dg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H0fv94/P; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-33d6cc6d2fcso426685f8f.2; Wed, 21 Feb 2024 04:39:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708519178; x=1709123978; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TVXQ0SykxtzeFN8y51Iqsk4cWHv4fF8waP8HNiw0MEc=; b=H0fv94/PnPtgLjRQE6+3xeWR0N8Rv3M1QocsELb4sJetNrTo2/h+1/sysb96RvStmx zYr5k05QZCmjPOHW8OHwegq73+MQR/aoY7Md6ckpv40JI+1FoRc9iE9Wt56Olj0wcVbA CO/lRMELTBJ64ej6M/tLEdVSIVEeeVPo4cMRctGYU27i05lV5SEFPcuTAadBeDggo3G3 A6i2UXv+spCGC9ojhbbPwOhMv7ia8alp9XtoqJ07rGg+sVejt/ls7326ZfS/+bcQYb5g E5Yz3fJ0ND2FxU1Qc0jVeseBhn6MJj7HaiplG3soxxnD9Tg/BS6bPn0tx3bMFQTRiIXf 11HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708519178; x=1709123978; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TVXQ0SykxtzeFN8y51Iqsk4cWHv4fF8waP8HNiw0MEc=; b=Hrgidrnf18HCCpsYl/TAwkUipwIywDwuiz3VdO41yCBSPpWvLDPDod4yLTukb9pKAh 9gSWUPzD0lR1J2yrgIGg9tmUek52eZiiWf1FtU+6HLmpz8mVvVita6f207HRJRjW7FN7 uYwoUeGRIMsPD1fsKzpULchQIX8CPEDJcPhZEcuJXnJZDC/bXZUJUkPBBorObYaQvToj 4ax7jU+p9ehBDiu1duqMyjLW8T8w3BhL/2f52toQxswlz6UrU6GnJ/GUS58LOcL+oW95 qIrBPBHvmu9XckYARbErhLtm1RA+mq8QAr/G2pN6sxw3HOVkIBNVBIS5uMjzMHgxLXnJ WTBQ== X-Forwarded-Encrypted: i=1; AJvYcCWepAUvnBb9o5l4AxOm/qXCjVr8hKpg6jq+YHRO3SKpGfJSovWHMo17cXS/JDimvRp5i+zkIeM1t3IW4RK7VM90REVGSGh/qxBfOlKXBSrmFCuFwhzIoSNLBkGPBHVAziJPg66FesLacA== X-Gm-Message-State: AOJu0YxPL/lucXU4qc8Q3XsottkO6rE1E1CL3ynEJwGJ3KlqINfk7TYt /4oXR5yEAh2nxSHrxzaNaKO1g/bdQYiXnLFg3uNVqARfOFC3V4kF/5x6R/Ff X-Received: by 2002:adf:ab07:0:b0:33d:3218:3378 with SMTP id q7-20020adfab07000000b0033d32183378mr8378085wrc.20.1708519178015; Wed, 21 Feb 2024 04:39:38 -0800 (PST) Received: from localhost (cpc154979-craw9-2-0-cust193.16-3.cable.virginm.net. [80.193.200.194]) by smtp.gmail.com with ESMTPSA id bu19-20020a056000079300b0033d3d9447e3sm11686342wrb.83.2024.02.21.04.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 04:39:37 -0800 (PST) From: Colin Ian King <colin.i.king@gmail.com> To: "Rafael J . Wysocki" <rafael@kernel.org>, Zhang Rui <rui.zhang@intel.com>, Len Brown <lenb@kernel.org>, linux-acpi@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] ACPI: thermal_lib: Add missing checks for errors in return code ret Date: Wed, 21 Feb 2024 12:39:36 +0000 Message-Id: <20240221123936.3421462-1-colin.i.king@gmail.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791512238325902735 X-GMAIL-MSGID: 1791512238325902735 |
Series |
[next] ACPI: thermal_lib: Add missing checks for errors in return code ret
|
|
Commit Message
Colin Ian King
Feb. 21, 2024, 12:39 p.m. UTC
Static analysis with clang scan build detected various return codes
being assigned and not checked. The calls to the trip point functions
probably should be error return checked as these can fail because
of unlikely issues such as invalid ACPI object names or ACPI value
evaluation failures.
Cleans up clang scan warnings, such as:
drivers/acpi/thermal_lib.c:106:9: warning: 2nd function call argument
is an uninitialized value [core.CallAndMessage]
return thermal_temp(ret, temp_decik, ret_temp);
Fixes: 6908097aa5a7 ("ACPI: thermal_lib: Add functions returning temperature in deci-Kelvin")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
Note: Not tested.
---
drivers/acpi/thermal_lib.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
Comments
On Wed, Feb 21, 2024 at 12:39:36PM +0000, Colin Ian King wrote: > Static analysis with clang scan build detected various return codes > being assigned and not checked. The calls to the trip point functions > probably should be error return checked as these can fail because > of unlikely issues such as invalid ACPI object names or ACPI value > evaluation failures. > > Cleans up clang scan warnings, such as: > drivers/acpi/thermal_lib.c:106:9: warning: 2nd function call argument > is an uninitialized value [core.CallAndMessage] > return thermal_temp(ret, temp_decik, ret_temp); > > > Fixes: 6908097aa5a7 ("ACPI: thermal_lib: Add functions returning temperature in deci-Kelvin") > Signed-off-by: Colin Ian King <colin.i.king@gmail.com> > --- > > Note: Not tested. > > --- > drivers/acpi/thermal_lib.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/acpi/thermal_lib.c b/drivers/acpi/thermal_lib.c > index 4e0519ca9739..4d27048ef075 100644 > --- a/drivers/acpi/thermal_lib.c > +++ b/drivers/acpi/thermal_lib.c > @@ -103,6 +103,9 @@ int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_tem > int temp_decik; > int ret = acpi_active_trip_temp(adev, id, &temp_decik); > > + if (ret) > + return ret; > + > return thermal_temp(ret, temp_decik, ret_temp); ^^^ The "ret" variable is checked at the start of the thermal_temp() function which means the code works the same before and after your patch. However, the static checker is correct that we are passing uninitialized data to this function, it's just never used if "ret" is non-zero. In this case, the rule is that if the function is parsed inline then it's not a bug, but if it's not inline then it is a bug. Technically, passing uninitialized data to a function is undefined behavior in C but Linus said that didn't really match with real life and that everyone should recognize that inlines are different and update the tools accordingly. (Something like that, I don't have the email in front of me). The other thing to consider is that tools like MEMSan (?) will see non-inline function calls and we're reading from uninitialized memory and trigger a warning for that. In this code, I suspect that thermal_temp() will be inlined so it's probably a false positive in Clang. regards, dan carpenter
Btw, in real life, in 2024, the compiler is going to automatically initialize "temp_decik" to zero. So we could just do: - int temp_decik; + int temp_decik = 0; That would silence the warning without affecting anything else at all. regards, dan carpenter
On Wed, Feb 21, 2024 at 2:19 PM Dan Carpenter <dan.carpenter@linaroorg> wrote: > > Btw, in real life, in 2024, the compiler is going to automatically > initialize "temp_decik" to zero. So we could just do: > > - int temp_decik; > + int temp_decik = 0; > > That would silence the warning without affecting anything else at all. Sounds good to me. Anyone willing to cut a patch for this?
On 22/02/2024 10:21, Rafael J. Wysocki wrote: > On Wed, Feb 21, 2024 at 2:19 PM Dan Carpenter <dan.carpenter@linaro.org> wrote: >> >> Btw, in real life, in 2024, the compiler is going to automatically >> initialize "temp_decik" to zero. So we could just do: >> >> - int temp_decik; >> + int temp_decik = 0; >> >> That would silence the warning without affecting anything else at all. > > Sounds good to me. > > Anyone willing to cut a patch for this? will do
diff --git a/drivers/acpi/thermal_lib.c b/drivers/acpi/thermal_lib.c index 4e0519ca9739..4d27048ef075 100644 --- a/drivers/acpi/thermal_lib.c +++ b/drivers/acpi/thermal_lib.c @@ -103,6 +103,9 @@ int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_tem int temp_decik; int ret = acpi_active_trip_temp(adev, id, &temp_decik); + if (ret) + return ret; + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp); @@ -122,6 +125,9 @@ int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp) int temp_decik; int ret = acpi_passive_trip_temp(adev, &temp_decik); + if (ret) + return ret; + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp); @@ -142,6 +148,9 @@ int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp) int temp_decik; int ret = acpi_hot_trip_temp(adev, &temp_decik); + if (ret) + return ret; + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp); @@ -161,6 +170,9 @@ int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp) int temp_decik; int ret = acpi_critical_trip_temp(adev, &temp_decik); + if (ret) + return ret; + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp);