Kernel-Janitors Archive on
 help / color / Atom feed
From: Dan Carpenter <>
To: Sudeep Holla <>
Cc: Cristian Marussi <>,
	"Jon Medhurst (Tixy)" <>,,,
Subject: [PATCH] firmware: arm_scpi: prevent ternary sign expansion bug
Date: Thu, 22 Apr 2021 12:02:29 +0300
Message-ID: <YIE7pdqV/h10tEAK@mwanda> (raw)

How type promotion works in ternary expressions is a bit tricky.
The problem is that scpi_clk_get_val() returns longs, "ret" is a int
which holds a negative error code, and le32_to_cpu() is an unsigned int.
We want the negative error code to be cast to a negative long.  But
because le32_to_cpu() is an u32 then "ret" is type promoted to u32 and
becomes a high positive and then it is promoted to long and it is still
a high positive value.

Fix this by getting rid of the ternary.

Fixes: 8cb7cf56c9fe ("firmware: add support for ARM System Control and Power Interface(SCPI) protocol")
Signed-off-by: Dan Carpenter <>
 drivers/firmware/arm_scpi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
index d0dee37ad522..3bf61854121d 100644
--- a/drivers/firmware/arm_scpi.c
+++ b/drivers/firmware/arm_scpi.c
@@ -552,8 +552,10 @@ static unsigned long scpi_clk_get_val(u16 clk_id)
 	ret = scpi_send_message(CMD_GET_CLOCK_VALUE, &le_clk_id,
 				sizeof(le_clk_id), &rate, sizeof(rate));
+	if (ret)
+		return ret;
-	return ret ? ret : le32_to_cpu(rate);
+	return le32_to_cpu(rate);
 static int scpi_clk_set_val(u16 clk_id, unsigned long rate)

             reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22  9:02 Dan Carpenter [this message]
2021-04-22 10:17 ` Cristian Marussi
2021-04-22 11:34   ` Cristian Marussi
2021-04-22 17:46 ` Sudeep Holla
2021-04-24  6:43   ` Dan Carpenter
2021-04-28 10:03 ` Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YIE7pdqV/h10tEAK@mwanda \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Kernel-Janitors Archive on

Archives are clonable:
	git clone --mirror kernel-janitors/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernel-janitors kernel-janitors/ \
	public-inbox-index kernel-janitors

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone