linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Andrzej Hajda <andrzej.hajda@intel.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	John Ogness <john.ogness@linutronix.de>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Brendan Jackman <jackmanb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
	Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Harry Yoo <harry.yoo@oracle.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: Re: [PATCH v2 3/5] drivers/core: simplify variadic args handling
Date: Tue, 2 Dec 2025 16:51:00 +0100	[thread overview]
Message-ID: <aS8K5DnumUA6XUs9@pathway.suse.cz> (raw)
In-Reply-To: <20251201-va_format_call-v2-3-2906f3093b60@intel.com>

I am adding Andy and Rasmus into Cc who are active vsprintf-related
code reviewers...

You might see the entire patchset at
https://lore.kernel.org/all/20251201-va_format_call-v2-0-2906f3093b60@intel.com/

On Mon 2025-12-01 10:31:24, Andrzej Hajda wrote:
> Changing argument type from va_list to struct va_format * allows
> to simplify variadic argument handling with va_format_call helper.
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 513e5ef8a6da..4d76b67a87e3 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4965,30 +4965,12 @@ define_dev_printk_level(_dev_info, KERN_INFO);
>  #endif
>  
>  static void __dev_probe_failed(const struct device *dev, int err, bool fatal,
> -			       const char *fmt, va_list vargsp)
> +			       const char *fmt, struct va_format *vaf)
>  {
> -	struct va_format vaf;
> -	va_list vargs;
> -
> -	/*
> -	 * On x86_64 and possibly on other architectures, va_list is actually a
> -	 * size-1 array containing a structure.  As a result, function parameter
> -	 * vargsp decays from T[1] to T*, and &vargsp has type T** rather than
> -	 * T(*)[1], which is expected by its assignment to vaf.va below.
> -	 *
> -	 * One standard way to solve this mess is by creating a copy in a local
> -	 * variable of type va_list and then using a pointer to that local copy
> -	 * instead, which is the approach employed here.
> -	 */
> -	va_copy(vargs, vargsp);
> -
> -	vaf.fmt = fmt;
> -	vaf.va = &vargs;

I am always a bit lost when using this API.
Why is it safe to remove the va_copy() here, please?

The va_format_call() uses va_start()/va_end() which is replacing
these calls in dev_err_probe() and dev_warn_probe().

It is possible that the original code was actually wrong because
it uses the same copy (&vaf) everywhere, see below.

>  	switch (err) {
>  	case -EPROBE_DEFER:
> -		device_set_deferred_probe_reason(dev, &vaf);

This function processes the arguments via:

  + device_set_deferred_probe_reason()
    + kasprintf()
      + va_start()/va_end()

> -		dev_dbg(dev, "error %pe: %pV", ERR_PTR(err), &vaf);

This function uses the already processed copy of the arguments.
IMHO, it might print a garbage because of this. IMHO, it should use
the original va_list() or might need its own copy.

Note that this call does not modify the va_list because it uses "%pV"
and vsprintf() creates its own copy in this case, see va_format()
in lib/vsprintf.c.

> +		device_set_deferred_probe_reason(dev, vaf);
> +		dev_dbg(dev, "error %pe: %pV", ERR_PTR(err), vaf);
>  		break;
>  
>  	case -ENOMEM:
> @@ -4998,13 +4980,11 @@ static void __dev_probe_failed(const struct device *dev, int err, bool fatal,
>  	default:
>  		/* Log fatal final failures as errors, otherwise produce warnings */
>  		if (fatal)
> -			dev_err(dev, "error %pe: %pV", ERR_PTR(err), &vaf);
> +			dev_err(dev, "error %pe: %pV", ERR_PTR(err), vaf);
>  		else
> -			dev_warn(dev, "error %pe: %pV", ERR_PTR(err), &vaf);
> +			dev_warn(dev, "error %pe: %pV", ERR_PTR(err), vaf);

This should be fine because of using "%pV".

>  		break;
>  	}
> -
> -	va_end(vargs);
>  }
>  
>  /**
> @@ -5042,15 +5022,7 @@ static void __dev_probe_failed(const struct device *dev, int err, bool fatal,
>   */
>  int dev_err_probe(const struct device *dev, int err, const char *fmt, ...)
>  {
> -	va_list vargs;
> -
> -	va_start(vargs, fmt);
> -
> -	/* Use dev_err() for logging when err doesn't equal -EPROBE_DEFER */
> -	__dev_probe_failed(dev, err, true, fmt, vargs);
> -
> -	va_end(vargs);
> -
> +	va_format_call(fmt, __dev_probe_failed, dev, err, true, fmt, va_format_arg);
>  	return err;
>  }
>  EXPORT_SYMBOL_GPL(dev_err_probe);
> @@ -5090,15 +5062,7 @@ EXPORT_SYMBOL_GPL(dev_err_probe);
>   */
>  int dev_warn_probe(const struct device *dev, int err, const char *fmt, ...)
>  {
> -	va_list vargs;
> -
> -	va_start(vargs, fmt);
> -
> -	/* Use dev_warn() for logging when err doesn't equal -EPROBE_DEFER */
> -	__dev_probe_failed(dev, err, false, fmt, vargs);
> -
> -	va_end(vargs);
> -
> +	va_format_call(fmt, __dev_probe_failed, dev, err, false, fmt, va_format_arg);
>  	return err;
>  }
>  EXPORT_SYMBOL_GPL(dev_warn_probe);

Best Regards,
Petr


  reply	other threads:[~2025-12-02 15:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-01  9:31 [PATCH v2 0/5] printk: add macros to simplify handling struct va_format Andrzej Hajda
2025-12-01  9:31 ` [PATCH v2 1/5] " Andrzej Hajda
2025-12-01  9:31 ` [PATCH v2 2/5] drivers/core: use va_format_call helper Andrzej Hajda
2025-12-01  9:31 ` [PATCH v2 3/5] drivers/core: simplify variadic args handling Andrzej Hajda
2025-12-02 15:51   ` Petr Mladek [this message]
2025-12-02 18:03     ` Hajda, Andrzej
2025-12-03 14:47       ` Andy Shevchenko
2025-12-03 18:07         ` Hajda, Andrzej
2025-12-01  9:31 ` [PATCH v2 4/5] mm: use va_format_call helper Andrzej Hajda
2025-12-01  9:31 ` [PATCH v2 5/5] mm: simplify variadic args handling Andrzej Hajda

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=aS8K5DnumUA6XUs9@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andrzej.hajda@intel.com \
    --cc=cl@gentwo.org \
    --cc=dakr@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=harry.yoo@oracle.com \
    --cc=jackmanb@google.com \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mhocko@suse.com \
    --cc=rafael@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=ziy@nvidia.com \
    /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