From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A940E3BFE55; Thu, 15 Jan 2026 17:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497186; cv=none; b=JWeGgmo68nHRC2HUxCYh19us62vFbyVjJgv2AS9ELSAsQNqOaQfOA4b41oBX91fInsDs6hTGG7WZ1eslOk2CRvckMP5MCb4j4lPfSEqNcTo2dGWNyK1AMvLcQlkPep9xwG/JK+XMGecx1rKAba4kbOSpk8v5a/5xwo3j3JehRzs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768497186; c=relaxed/simple; bh=weYvz//yoJoA5hF6VeXWx5KGNN2FDqTgx1kk6qxb0BE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pn3ygjeGSGpuXJNg11Dk7aWdsSIU0m05mq3t4ycsnvpGj89lnKnkWFJhm7l7doLS0X4lw3/6x/l9Yk8uG8jn/eP0BLK+PAZDsXqIbllIqgwMu0hF0IDrDcXSQfB7g5Wknp6mtbih0/Yyf8xMYJqUmMILqMdvxlXj3VFFrc0LmNY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=a57vvd92; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="a57vvd92" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37537C116D0; Thu, 15 Jan 2026 17:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1768497186; bh=weYvz//yoJoA5hF6VeXWx5KGNN2FDqTgx1kk6qxb0BE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a57vvd92GJ55cvjDp2bdEeA5hcLXLg+/38c5Odhpmy5prPhQxSO2/iueAF6RJoL79 02seGwmLRdISfr2DC+7n8FqWhNh+yqJkEuQbzRgdFhitVCcX8ieM2ne/RAEte2QLr3 KTyx1s4YozKPo+KKFHC/2403QmatkdJXF2dYJ8UA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sumeet Pawnikar , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.1 67/72] powercap: fix sscanf() error return value handling Date: Thu, 15 Jan 2026 17:49:17 +0100 Message-ID: <20260115164145.932851162@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115164143.482647486@linuxfoundation.org> References: <20260115164143.482647486@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sumeet Pawnikar [ Upstream commit efc4c35b741af973de90f6826bf35d3b3ac36bf1 ] Fix inconsistent error handling for sscanf() return value check. Implicit boolean conversion is used instead of explicit return value checks. The code checks if (!sscanf(...)) which is incorrect because: 1. sscanf returns the number of successfully parsed items 2. On success, it returns 1 (one item passed) 3. On failure, it returns 0 or EOF 4. The check 'if (!sscanf(...))' is wrong because it treats success (1) as failure All occurrences of sscanf() now uses explicit return value check. With this behavior it returns '-EINVAL' when parsing fails (returns 0 or EOF), and continues when parsing succeeds (returns 1). Signed-off-by: Sumeet Pawnikar [ rjw: Subject and changelog edits ] Link: https://patch.msgid.link/20251207151549.202452-1-sumeet4linux@gmail.com Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/powercap/powercap_sys.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c index d7dadcaa3736b..72fa1f5affcea 100644 --- a/drivers/powercap/powercap_sys.c +++ b/drivers/powercap/powercap_sys.c @@ -67,7 +67,7 @@ static ssize_t show_constraint_##_attr(struct device *dev, \ int id; \ struct powercap_zone_constraint *pconst;\ \ - if (!sscanf(dev_attr->attr.name, "constraint_%d_", &id)) \ + if (sscanf(dev_attr->attr.name, "constraint_%d_", &id) != 1) \ return -EINVAL; \ if (id >= power_zone->const_id_cnt) \ return -EINVAL; \ @@ -92,7 +92,7 @@ static ssize_t store_constraint_##_attr(struct device *dev,\ int id; \ struct powercap_zone_constraint *pconst;\ \ - if (!sscanf(dev_attr->attr.name, "constraint_%d_", &id)) \ + if (sscanf(dev_attr->attr.name, "constraint_%d_", &id) != 1) \ return -EINVAL; \ if (id >= power_zone->const_id_cnt) \ return -EINVAL; \ @@ -161,7 +161,7 @@ static ssize_t show_constraint_name(struct device *dev, ssize_t len = -ENODATA; struct powercap_zone_constraint *pconst; - if (!sscanf(dev_attr->attr.name, "constraint_%d_", &id)) + if (sscanf(dev_attr->attr.name, "constraint_%d_", &id) != 1) return -EINVAL; if (id >= power_zone->const_id_cnt) return -EINVAL; -- 2.51.0