Nouveau Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Muhammed Sariyildiz <asiyee994@gmail.com>
To: lyude@redhat.com, dakr@kernel.org
Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org,
	Muhammed Sariyildiz <asiyee994@gmail.com>
Subject: [PATCH] drm/nouveau/clk/gk20a: fix undefined behaviour in signed left shift
Date: Mon, 10 Aug 2026 22:42:47 +0100	[thread overview]
Message-ID: <20260810214247.21416-1-asiyee994@gmail.com> (raw)

MASK(w) expands as ((1 << (w)) - 1), and GPC2CLK_OUT_SDIV14_INDIV4_MODE
is defined as plain 1. Both are used, via GPC2CLK_OUT_INIT_MASK and
GPC2CLK_OUT_INIT_VAL in gk20a_clk_prog() (and reused by gm20b, which
includes gk20a.h), to compute:

	1 << 31

Left-shifting a signed int into its sign bit is undefined behaviour
per the C standard (ISO C11 6.5.7p4), and is flagged by UBSan and
static analysis tools such as cppcheck (shiftTooManyBitsSigned). Make
the shifted operand unsigned to fix it, matching the pattern used
elsewhere in the kernel for register bitfield masks.

No functional change intended.

Found via static analysis (cppcheck --enable=portability) while
auditing nvkm/subdev/clk for correctness issues.

Signed-off-by: Muhammed Sariyildiz <asiyee994@gmail.com>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/clk/gk20a.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gk20a.h b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gk20a.h
index ea5b0ba..7a93f9f 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gk20a.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/gk20a.h
@@ -27,7 +27,7 @@
 #define KHZ (1000)
 #define MHZ (KHZ * 1000)
 
-#define MASK(w)	((1 << (w)) - 1)
+#define MASK(w)	((1U << (w)) - 1)
 
 #define GK20A_CLK_GPC_MDIV 1000
 
@@ -79,7 +79,7 @@
 #define GPC2CLK_OUT			(SYS_GPCPLL_CFG_BASE + 0x250)
 #define GPC2CLK_OUT_SDIV14_INDIV4_WIDTH	1
 #define GPC2CLK_OUT_SDIV14_INDIV4_SHIFT	31
-#define GPC2CLK_OUT_SDIV14_INDIV4_MODE	1
+#define GPC2CLK_OUT_SDIV14_INDIV4_MODE	1U
 #define GPC2CLK_OUT_VCODIV_WIDTH	6
 #define GPC2CLK_OUT_VCODIV_SHIFT	8
 #define GPC2CLK_OUT_VCODIV1		0
-- 
2.43.0


             reply	other threads:[~2026-08-11 15:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 21:42 Muhammed Sariyildiz [this message]
2026-08-26 18:02 ` [PATCH] drm/nouveau/clk/gk20a: fix undefined behaviour in signed left shift Asiye Sarıyıldız

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20260810214247.21416-1-asiyee994@gmail.com \
    --to=asiyee994@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lyude@redhat.com \
    --cc=nouveau@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox