linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Georgi Djakov <djakov@kernel.org>
To: Mike Tipton <quic_mdtipton@quicinc.com>,
	gregkh@linuxfoundation.org, rafael@kernel.org, corbet@lwn.net
Cc: linux-pm@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	quic_okukatla@quicinc.com, quic_viveka@quicinc.com,
	peterz@infradead.org, quic_pkondeti@quicinc.com
Subject: Re: [PATCH v3 1/3] debugfs: Add write support to debugfs_create_str()
Date: Fri, 11 Aug 2023 10:46:34 +0300	[thread overview]
Message-ID: <58ea6863-53cd-228b-1474-f67b0bb134f0@kernel.org> (raw)
In-Reply-To: <20230807142914.12480-2-quic_mdtipton@quicinc.com>

On 7.08.23 17:29, Mike Tipton wrote:
> Currently, debugfs_create_str() only supports reading strings from
> debugfs. Add support for writing them as well.
> 
> Based on original implementation by Peter Zijlstra [0]. Write support
> was present in the initial patch version, but dropped in v2 due to lack
> of users. We have a user now, so reintroduce it.
> 
> [0] https://lore.kernel.org/all/YF3Hv5zXb%2F6lauzs@hirez.programming.kicks-ass.net/
> 

Hi Greg,

Looks like the original code was reviewed two years ago (not sure if it
counts). But in any case, i need an ack from you to apply this.

There is no build dependency with the rest of the patches (but there is a
functional one). It should be also fine if you apply it directly, if you
prefer so?

Thanks,
Georgi

> Signed-off-by: Mike Tipton <quic_mdtipton@quicinc.com>
> ---
>   fs/debugfs/file.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
> index b7711888dd17..87b3753aa4b1 100644
> --- a/fs/debugfs/file.c
> +++ b/fs/debugfs/file.c
> @@ -904,8 +904,52 @@ EXPORT_SYMBOL_GPL(debugfs_create_str);
>   static ssize_t debugfs_write_file_str(struct file *file, const char __user *user_buf,
>   				      size_t count, loff_t *ppos)
>   {
> -	/* This is really only for read-only strings */
> -	return -EINVAL;
> +	struct dentry *dentry = F_DENTRY(file);
> +	char *old, *new = NULL;
> +	int pos = *ppos;
> +	int r;
> +
> +	r = debugfs_file_get(dentry);
> +	if (unlikely(r))
> +		return r;
> +
> +	old = *(char **)file->private_data;
> +
> +	/* only allow strict concatenation */
> +	r = -EINVAL;
> +	if (pos && pos != strlen(old))
> +		goto error;
> +
> +	r = -E2BIG;
> +	if (pos + count + 1 > PAGE_SIZE)
> +		goto error;
> +
> +	r = -ENOMEM;
> +	new = kmalloc(pos + count + 1, GFP_KERNEL);
> +	if (!new)
> +		goto error;
> +
> +	if (pos)
> +		memcpy(new, old, pos);
> +
> +	r = -EFAULT;
> +	if (copy_from_user(new + pos, user_buf, count))
> +		goto error;
> +
> +	new[pos + count] = '\0';
> +	strim(new);
> +
> +	rcu_assign_pointer(*(char **)file->private_data, new);
> +	synchronize_rcu();
> +	kfree(old);
> +
> +	debugfs_file_put(dentry);
> +	return count;
> +
> +error:
> +	kfree(new);
> +	debugfs_file_put(dentry);
> +	return r;
>   }
>   
>   static const struct file_operations fops_str = {


  reply	other threads:[~2023-08-11  7:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 14:29 [PATCH v3 0/3] Add interconnect debugfs client Mike Tipton
2023-08-07 14:29 ` [PATCH v3 1/3] debugfs: Add write support to debugfs_create_str() Mike Tipton
2023-08-11  7:46   ` Georgi Djakov [this message]
2023-08-12 10:36     ` Greg KH
2023-08-12 10:37       ` Greg KH
2023-08-12 10:40   ` Greg KH
2023-08-12 13:25     ` Georgi Djakov
2023-08-18 10:05     ` Georgi Djakov
2023-08-22 17:46       ` Greg KH
2023-08-07 14:29 ` [PATCH v3 2/3] interconnect: Reintroduce icc_get() Mike Tipton
2023-08-07 14:29 ` [PATCH v3 3/3] interconnect: Add debugfs test client Mike Tipton

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=58ea6863-53cd-228b-1474-f67b0bb134f0@kernel.org \
    --to=djakov@kernel.org \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=quic_mdtipton@quicinc.com \
    --cc=quic_okukatla@quicinc.com \
    --cc=quic_pkondeti@quicinc.com \
    --cc=quic_viveka@quicinc.com \
    --cc=rafael@kernel.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;
as well as URLs for NNTP newsgroup(s).