public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Remo Senekowitsch <remo@buenzli.dev>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	linux-kernel@vger.kernel.org
Subject: Re: Exporting functions from vsprintf.c for Rust
Date: Fri, 11 Apr 2025 11:42:23 +0200	[thread overview]
Message-ID: <Z_jj_8vvmWY-WuTU@pathway.suse.cz> (raw)
In-Reply-To: <D931ZH9KRY2E.2D7HN6QWELGFJ@buenzli.dev>

Adding few more people and lkml into Cc.

On Thu 2025-04-10 17:10:57, Remo Senekowitsch wrote:
> Hi
> 
> I need to print the full path of a fwnode in Rust. One approach is to
> export it, as shown below. Is this acceptable to you in principle?
> 
> There are also some intermediary solutions like not providing a header
> and or prefixing `__`.
> 
> Thanks,
> Remo
> 
> ---
> diff --git a/include/linux/vsprintf.h b/include/linux/vsprintf.h
> new file mode 100644
> index 000000000..b37b11868
> --- /dev/null
> +++ b/include/linux/vsprintf.h

Just for record. Steven suggested to use include/linux/sprintf.h
instead because it was already used for another vsprintf APIs.

> @@ -0,0 +1,4 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
> +			      char *end);

Honestly, I do not have a good feeling about exporting the internal
vsprintf() functions. They have a very specific semantic.

Especially, they return pointer to the next-to-write character.
And it might be even beyond the given *end pointer. It is because, for
example, vsnprintf() returns the number of characters which would
have been written to the buffer when it was big enough.

Instead, I suggest to create a wrapper which would have a sane
semantic and call scnprintf() internally. Something like:

int fwnode_full_name_to_string(char *buf, size_t size,
			       struct fwnode_handle *fwnode)
{
	return scnprintf(buf, size, "%pfwf", fwnode);
}

I am just not sure where to put it. It might be vsprintf.c.
But I think that a better place would be drivers/base/property.c.
For example, I see a "similar" fwnode_property_match_string()
already there.

Best Regards,
Petr


> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 56fe96319..3b4d0065a 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -43,6 +43,7 @@
>  #include <linux/compiler.h>
>  #include <linux/property.h>
>  #include <linux/notifier.h>
> +#include <linux/vsprintf.h>
>  #ifdef CONFIG_BLOCK
>  #include <linux/blkdev.h>
>  #endif
> @@ -2103,7 +2104,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,
>  	return format_flags(buf, end, flags, names);
>  }
>  
> -static noinline_for_stack
> +noinline_for_stack
>  char *fwnode_full_name_string(struct fwnode_handle *fwnode, char *buf,
>  			      char *end)
>  {
> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
> index 4bd02abd2..24a565ffd 100644
> --- a/rust/bindings/bindings_helper.h
> +++ b/rust/bindings/bindings_helper.h
> @@ -38,6 +38,7 @@
>  #include <linux/security.h>
>  #include <linux/slab.h>
>  #include <linux/tracepoint.h>
> +#include <linux/vsprintf.h>
>  #include <linux/wait.h>
>  #include <linux/workqueue.h>
>  #include <trace/events/rust_sample.h>

       reply	other threads:[~2025-04-11  9:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <D931ZH9KRY2E.2D7HN6QWELGFJ@buenzli.dev>
2025-04-11  9:42 ` Petr Mladek [this message]
2025-04-11 11:36   ` Exporting functions from vsprintf.c for Rust Remo Senekowitsch
     [not found]     ` <CAKwiHFi_egfePDdXQEtYNvO-U65O==MosHNQ7Vm4F6iudJs95g@mail.gmail.com>
2025-04-14  6:59       ` Andy Shevchenko
2025-04-14 11:47       ` Remo Senekowitsch

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=Z_jj_8vvmWY-WuTU@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=remo@buenzli.dev \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.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