All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhou Wang <wangzhou1@hisilicon.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] crypto: hisilicon/qm - allow smaller reads in debugfs
Date: Fri, 29 May 2020 06:24:01 +0000	[thread overview]
Message-ID: <5ED0AA81.5080105@hisilicon.com> (raw)
In-Reply-To: <20200528123703.GA1219412@mwanda>

On 2020/5/28 20:37, Dan Carpenter wrote:
> Originally this code rejected any read less than 256 bytes.  There
> is no need for this artificial limit.
> 
> Also I have changed the snprintf() functions to scnprintf().  The
> difference is that snprintf() returns the number of bytes which would
> have been copied if there were enough space and scnprintf() returns the
> number of bytes which were actually copied.  It doesn't matter here
> because the strings are very short so they can't go over 256 bytes.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Looks good to me, thanks!
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>

> ---
>  drivers/crypto/hisilicon/qm.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
> index a781c02251980..9c0c9f500d91d 100644
> --- a/drivers/crypto/hisilicon/qm.c
> +++ b/drivers/crypto/hisilicon/qm.c
> @@ -1076,16 +1076,15 @@ static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
>  	if (*pos)
>  		return 0;
>  
> -	if (count < QM_DBG_READ_LEN)
> -		return -ENOSPC;
> -
> -	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n",
> +	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n",
>  		       "Please echo help to cmd to get help information");
>  
> +	len = min_t(size_t, len, count);
>  	if (copy_to_user(buffer, buf, len))
>  		return -EFAULT;
>  
> -	return (*pos = len);
> +	*pos = len;
> +	return len;
>  }
>  
>  static void *qm_ctx_alloc(struct hisi_qm *qm, size_t ctx_size,
> @@ -2710,19 +2709,18 @@ static ssize_t qm_status_read(struct file *filp, char __user *buffer,
>  	if (*pos)
>  		return 0;
>  
> -	if (count < QM_DBG_READ_LEN)
> -		return -ENOSPC;
> -
>  	val = atomic_read(&qm->status.flags);
> -	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
> +	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
>  	if (!len)
>  		return -EFAULT;
>  
> +	len = min_t(size_t, len, count);
>  	cp_len = copy_to_user(buffer, buf, len);
>  	if (cp_len)
>  		return -EFAULT;
>  
> -	return (*pos = len);
> +	*pos = len;
> +	return len;
>  }
>  
>  static const struct file_operations qm_status_fops = {
> 

WARNING: multiple messages have this Message-ID (diff)
From: Zhou Wang <wangzhou1@hisilicon.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<kernel-janitors@vger.kernel.org>
Subject: Re: [PATCH] crypto: hisilicon/qm - allow smaller reads in debugfs
Date: Fri, 29 May 2020 14:24:01 +0800	[thread overview]
Message-ID: <5ED0AA81.5080105@hisilicon.com> (raw)
In-Reply-To: <20200528123703.GA1219412@mwanda>

On 2020/5/28 20:37, Dan Carpenter wrote:
> Originally this code rejected any read less than 256 bytes.  There
> is no need for this artificial limit.
> 
> Also I have changed the snprintf() functions to scnprintf().  The
> difference is that snprintf() returns the number of bytes which would
> have been copied if there were enough space and scnprintf() returns the
> number of bytes which were actually copied.  It doesn't matter here
> because the strings are very short so they can't go over 256 bytes.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Looks good to me, thanks!
Reviewed-by: Zhou Wang <wangzhou1@hisilicon.com>

> ---
>  drivers/crypto/hisilicon/qm.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
> index a781c02251980..9c0c9f500d91d 100644
> --- a/drivers/crypto/hisilicon/qm.c
> +++ b/drivers/crypto/hisilicon/qm.c
> @@ -1076,16 +1076,15 @@ static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
>  	if (*pos)
>  		return 0;
>  
> -	if (count < QM_DBG_READ_LEN)
> -		return -ENOSPC;
> -
> -	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n",
> +	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n",
>  		       "Please echo help to cmd to get help information");
>  
> +	len = min_t(size_t, len, count);
>  	if (copy_to_user(buffer, buf, len))
>  		return -EFAULT;
>  
> -	return (*pos = len);
> +	*pos = len;
> +	return len;
>  }
>  
>  static void *qm_ctx_alloc(struct hisi_qm *qm, size_t ctx_size,
> @@ -2710,19 +2709,18 @@ static ssize_t qm_status_read(struct file *filp, char __user *buffer,
>  	if (*pos)
>  		return 0;
>  
> -	if (count < QM_DBG_READ_LEN)
> -		return -ENOSPC;
> -
>  	val = atomic_read(&qm->status.flags);
> -	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
> +	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
>  	if (!len)
>  		return -EFAULT;
>  
> +	len = min_t(size_t, len, count);
>  	cp_len = copy_to_user(buffer, buf, len);
>  	if (cp_len)
>  		return -EFAULT;
>  
> -	return (*pos = len);
> +	*pos = len;
> +	return len;
>  }
>  
>  static const struct file_operations qm_status_fops = {
> 

  reply	other threads:[~2020-05-29  6:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28 12:37 [PATCH] crypto: hisilicon/qm - allow smaller reads in debugfs Dan Carpenter
2020-05-28 12:37 ` Dan Carpenter
2020-05-29  6:24 ` Zhou Wang [this message]
2020-05-29  6:24   ` Zhou Wang
2020-06-01  2:19 ` Shukun Tan
2020-06-01  2:19   ` Shukun Tan

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=5ED0AA81.5080105@hisilicon.com \
    --to=wangzhou1@hisilicon.com \
    --cc=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.