From: Nathan Chancellor <nathan@kernel.org>
To: Thomas Zimmermann <tzimmermann@suse.de>,
Javier Martinez Canillas <javierm@redhat.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>
Cc: dri-devel@lists.freedesktop.org, llvm@lists.linux.dev,
patches@lists.linux.dev, Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH v2] drm/sysfb: efidrm: Avoid clang -Wsometimes-uninitialized in efidrm_device_create()
Date: Thu, 10 Apr 2025 10:43:08 -0700 [thread overview]
Message-ID: <20250410-efidrm-avoid-uninit-screen_info-warning-v2-1-b79646f58c24@kernel.org> (raw)
Clang warns (or errors with CONFIG_WERROR=y):
drivers/gpu/drm/sysfb/efidrm.c:353:11: error: variable 'screen_base' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
353 | else if (mem_flags & EFI_MEMORY_WB)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/sysfb/efidrm.c:356:7: note: uninitialized use occurs here
356 | if (!screen_base)
| ^~~~~~~~~~~
drivers/gpu/drm/sysfb/efidrm.c:353:7: note: remove the 'if' if its condition is always true
353 | else if (mem_flags & EFI_MEMORY_WB)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354 | screen_base = devm_memremap(&pdev->dev, mem->start, resource_size(mem),
drivers/gpu/drm/sysfb/efidrm.c:261:27: note: initialize the variable 'screen_base' to silence this warning
261 | void __iomem *screen_base;
| ^
| = NULL
efidrm_get_mem_flags() can only return a mask that has at least one of
the tested values set so the else case is impossible but clang's static
analysis runs before inlining so it cannot know that.
Initialize screen_base to NULL and add a defensive error message in case
mem_flags were ever returned without one of the four valid values.
Fixes: 32ae90c66fb6 ("drm/sysfb: Add efidrm for EFI displays")
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Changes in v2:
- Upgrade drm_warn() to drm_err() and adjust message (Thomas).
- Carry forward Thomas's reviewed-by.
- Link to v1: https://lore.kernel.org/r/20250409-efidrm-avoid-uninit-screen_info-warning-v1-1-67babb19d831@kernel.org
---
drivers/gpu/drm/sysfb/efidrm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/sysfb/efidrm.c b/drivers/gpu/drm/sysfb/efidrm.c
index af90064a4c04..3cfd5d2cbf48 100644
--- a/drivers/gpu/drm/sysfb/efidrm.c
+++ b/drivers/gpu/drm/sysfb/efidrm.c
@@ -258,7 +258,7 @@ static struct efidrm_device *efidrm_device_create(struct drm_driver *drv,
struct drm_sysfb_device *sysfb;
struct drm_device *dev;
struct resource *mem = NULL;
- void __iomem *screen_base;
+ void __iomem *screen_base = NULL;
struct drm_plane *primary_plane;
struct drm_crtc *crtc;
struct drm_encoder *encoder;
@@ -353,6 +353,8 @@ static struct efidrm_device *efidrm_device_create(struct drm_driver *drv,
else if (mem_flags & EFI_MEMORY_WB)
screen_base = devm_memremap(&pdev->dev, mem->start, resource_size(mem),
MEMREMAP_WB);
+ else
+ drm_err(dev, "invalid mem_flags: 0x%llx\n", mem_flags);
if (!screen_base)
return ERR_PTR(-ENOMEM);
iosys_map_set_vaddr_iomem(&sysfb->fb_addr, screen_base);
---
base-commit: e8bf4a1bdaeadb28d13b9a2bcfd5910fda06eede
change-id: 20250409-efidrm-avoid-uninit-screen_info-warning-d62ef67ce3c5
Best regards,
--
Nathan Chancellor <nathan@kernel.org>
next reply other threads:[~2025-04-10 17:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-10 17:43 Nathan Chancellor [this message]
2025-04-11 7:31 ` [PATCH v2] drm/sysfb: efidrm: Avoid clang -Wsometimes-uninitialized in efidrm_device_create() Thomas Zimmermann
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=20250410-efidrm-avoid-uninit-screen_info-warning-v2-1-b79646f58c24@kernel.org \
--to=nathan@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=llvm@lists.linux.dev \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=patches@lists.linux.dev \
--cc=tzimmermann@suse.de \
/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