lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aKZUy_XZxHKLQUAS@google.com>
Date: Wed, 20 Aug 2025 23:05:47 +0000
From: Carlos Llamas <cmllamas@...gle.com>
To: Lucas De Marchi <lucas.demarchi@...el.com>
Cc: Thomas Hellström <thomas.hellstrom@...ux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@...el.com>,
	David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
	Matt Atwood <matthew.s.atwood@...el.com>, kernel-team@...roid.com,
	linux-kernel@...r.kernel.org,
	"open list:INTEL DRM XE DRIVER (Lunar Lake and newer)" <intel-xe@...ts.freedesktop.org>,
	"open list:DRM DRIVERS" <dri-devel@...ts.freedesktop.org>
Subject: Re: [PATCH] drm/xe: replace basename() with portable strrchr()

On Wed, Aug 20, 2025 at 04:15:47PM -0500, Lucas De Marchi wrote:
> On Wed, Aug 20, 2025 at 08:16:11PM +0000, Carlos Llamas wrote:
> > Commit b0a2ee5567ab ("drm/xe: prepare xe_gen_wa_oob to be multi-use")
> > introduced a call to basename(). The GNU version of this function is not
> > portable and fails to build with alternative libc implementations like
> > musl or bionic. This causes the following build error:
> > 
> >  drivers/gpu/drm/xe/xe_gen_wa_oob.c:130:12: error: assignment to ‘const char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
> >    130 |         fn = basename(fn);
> >        |            ^
> > 
> > While a POSIX version of basename() could be used, it would require a
> > separate header plus the behavior differs from GNU version in that it
> > might modify its argument. Not great.
> > 
> > Instead replace basename() with a strrchr() based implementation which
> > provides the same functionality and avoid portability issues.
> > 
> > Fixes: b0a2ee5567ab ("drm/xe: prepare xe_gen_wa_oob to be multi-use")
> > Signed-off-by: Carlos Llamas <cmllamas@...gle.com>
> > ---
> > drivers/gpu/drm/xe/xe_gen_wa_oob.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpu/drm/xe/xe_gen_wa_oob.c b/drivers/gpu/drm/xe/xe_gen_wa_oob.c
> > index 6581cb0f0e59..0a94a045bcea 100644
> > --- a/drivers/gpu/drm/xe/xe_gen_wa_oob.c
> > +++ b/drivers/gpu/drm/xe/xe_gen_wa_oob.c
> > @@ -125,9 +125,11 @@ static int parse(FILE *input, FILE *csource, FILE *cheader, char *prefix)
> > 
> > static int fn_to_prefix(const char *fn, char *prefix, size_t size)
> > {
> > +	const char *base;
> > 	size_t len;
> > 
> > -	fn = basename(fn);
> > +	base = strrchr(fn, '/');
> > +	fn = base ? base + 1 : fn;
> 
> I think just a xbasename() helper like we've added in kmod would be
> preferred:
> https://github.com/kmod-project/kmod/commit/11eb9bc67c319900ab00523997323a97d2d08ad2
> 
> Alternativelly add it somewhere that can be shared across the userspace
> tools in the kernel tree to fix the mess that we have here:
> 
> 	git grep basename -- tools/**.c
> 

This sounds like a nice idea. However, there is no "centralized" shared
includes/ across the userspace tools that I'm aware of?

> Some dup the arg simply to be able to use the libgen.h version, some use
> one or the other on purpose, etc etc.
> 

Yeah, and I can force the POSIX version if you prefer. I just personally
think the strrchr() alternative ends up being simpler.

--
Carlos Llamas

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ