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] [thread-next>] [day] [month] [year] [list]
Message-ID: <aQNvjqJGqFO30JTx@smile.fi.intel.com>
Date: Thu, 30 Oct 2025 16:00:46 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Christian Marangi <ansuelsmth@...il.com>
Cc: Ilia Lin <ilia.lin@...nel.org>, "Rafael J. Wysocki" <rafael@...nel.org>,
	Viresh Kumar <viresh.kumar@...aro.org>,
	Bjorn Andersson <andersson@...nel.org>,
	Konrad Dybcio <konradybcio@...nel.org>,
	Raag Jadav <raag.jadav@...el.com>, Arnd Bergmann <arnd@...db.de>,
	linux-arm-msm@...r.kernel.org, linux-pm@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/3] err.h: add ERR_PTR_CONST macro

On Thu, Oct 30, 2025 at 11:22:11AM +0100, Christian Marangi wrote:
> On Thu, Oct 30, 2025 at 10:27:38AM +0200, Andy Shevchenko wrote:
> > On Wed, Oct 29, 2025 at 04:38:53PM +0100, Christian Marangi wrote:
> > > On Wed, Oct 29, 2025 at 05:32:48PM +0200, Andy Shevchenko wrote:
> > > > On Wed, Oct 29, 2025 at 02:33:19PM +0100, Christian Marangi wrote:
> > > > > Add ERR_PTR_CONST macro to initialize global variables with error
> > > > 
> > > > ERR_PTR_CONST()
> > > > 
> > > > > pointers. This might be useful for specific case where there is a global
> > > > > variables initialized to an error condition and then later set to the
> > > > > real handle once probe finish/completes.
> > > > 
> > > > Okay, this has two caveats:
> > > > 
> > > > 1) naming is bad as it suggests something about const qualifier (and not, it's
> > > > not about that at all);
> > > > 
> > > > 2) it doesn't explain what's wrong with ERR_PTR().
> > > >
> > > 
> > > It can't be used for global variables as it does cause compilation
> > > error.
> > 
> > Can you show an example, please?
> 
> drivers/soc/qcom/smem.c:361:35: error: initializer element is not constant
>   361 | static struct qcom_smem *__smem = ERR_PTR(-EPROBE_DEFER);
>       |                                   ^~~~~~~
> make[9]: *** [scripts/Makefile.build:229: drivers/soc/qcom/smem.o] Error 1
> 
> You want me to add this to the commit? Or any hint to better reword this
> so it's more understandable?

Just the first line would be enough.
And perhaps better naming for the macro, but I have no ideas from top of my
head right now. Ah, actually I do. We call those either INIT_*() or DEFINE_*()
with the difference that INIT_*() works like your proposed idea. i.e. returns
a suitable value, but DEFINE_*() incorporates a variable and a type.

I think the INIT_ERR_PTR() is what we want as a name.

> > > I wanted to use ERR_PTR to set the __smem handle instead of freecode
> > > (void *) -EPROBE_DEFER and notice the compiler doesn't like using
> > > ERR_PTR().
> > > 
> > > Then the problem is clear as static declaration require constant value
> > > for initialization and ERR_PTR is a inline function.
> > > 
> > > This is why ERR_PTR_CONST following the pattern that was used for
> > > FIELD_PREP -> FIELD_PREP_CONST that was also introduced for similar
> > > case.
> > > 
> > > So yes this is specific for case of static global variables.

-- 
With Best Regards,
Andy Shevchenko



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ