kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] crypto: hisilicon - allow smaller reads in debugfs
@ 2020-06-02 13:54 Dan Carpenter
  2020-06-05  1:19 ` Shukun Tan
  2020-06-18  7:56 ` Herbert Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Carpenter @ 2020-06-02 13:54 UTC (permalink / raw)
  To: Zhou Wang, Shukun Tan
  Cc: Herbert Xu, David S. Miller, linux-crypto, linux-kernel, kernel-janitors

Originally this code rejected any read less than 256 bytes.  There
is no need for this artificial limit.  We should just use the normal
helper functions to read a string from the kernel.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: Use simple_read_from_buffer().  The v1 was slightly half arsed
because I left the original check for:

	if (*pos)
		return 0;

So it could result in partial reads.  The new code means that if you
want to read the buffer one byte at a time, that's fine or if you want
to read it in one 256 byte chunk that's also fine.  Plus it deletes 21
lines of code and is a lot cleaner.

 drivers/crypto/hisilicon/qm.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index 9bb263cec6c30..13ccb9e29a2e1 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -1064,19 +1064,10 @@ static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
 	char buf[QM_DBG_READ_LEN];
 	int len;
 
-	if (*pos)
-		return 0;
-
-	if (count < QM_DBG_READ_LEN)
-		return -ENOSPC;
+	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n",
+			"Please echo help to cmd to get help information");
 
-	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n",
-		       "Please echo help to cmd to get help information");
-
-	if (copy_to_user(buffer, buf, len))
-		return -EFAULT;
-
-	return (*pos = len);
+	return simple_read_from_buffer(buffer, count, pos, buf, len);
 }
 
 static void *qm_ctx_alloc(struct hisi_qm *qm, size_t ctx_size,
@@ -2691,24 +2682,12 @@ static ssize_t qm_status_read(struct file *filp, char __user *buffer,
 {
 	struct hisi_qm *qm = filp->private_data;
 	char buf[QM_DBG_READ_LEN];
-	int val, cp_len, len;
-
-	if (*pos)
-		return 0;
-
-	if (count < QM_DBG_READ_LEN)
-		return -ENOSPC;
+	int val, len;
 
 	val = atomic_read(&qm->status.flags);
-	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
-	if (!len)
-		return -EFAULT;
-
-	cp_len = copy_to_user(buffer, buf, len);
-	if (cp_len)
-		return -EFAULT;
+	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
 
-	return (*pos = len);
+	return simple_read_from_buffer(buffer, count, pos, buf, len);
 }
 
 static const struct file_operations qm_status_fops = {
-- 
2.26.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] crypto: hisilicon - allow smaller reads in debugfs
  2020-06-02 13:54 [PATCH v2] crypto: hisilicon - allow smaller reads in debugfs Dan Carpenter
@ 2020-06-05  1:19 ` Shukun Tan
  2020-06-05  9:13   ` Dan Carpenter
  2020-06-18  7:56 ` Herbert Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Shukun Tan @ 2020-06-05  1:19 UTC (permalink / raw)
  To: b6da310b-e633-9f74-f7af-7791d803aaf5, Zhou Wang
  Cc: Herbert Xu, David S. Miller, linux-crypto, linux-kernel, kernel-janitors

Hi Dan,

On 2020/6/2 21:54, Dan Carpenter wrote:
> Originally this code rejected any read less than 256 bytes.  There
> is no need for this artificial limit.  We should just use the normal
> helper functions to read a string from the kernel.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: Use simple_read_from_buffer().  The v1 was slightly half arsed
> because I left the original check for:
> 
> 	if (*pos)
> 		return 0;
> 
> So it could result in partial reads.  The new code means that if you
> want to read the buffer one byte at a time, that's fine or if you want
> to read it in one 256 byte chunk that's also fine.  Plus it deletes 21
> lines of code and is a lot cleaner.
> 

In fact, In our original design, we do not hope the user do the partial reads.
Thank you for your work, but I still insist on adding this limit.

Thanks,
Shukun

>  drivers/crypto/hisilicon/qm.c | 33 ++++++---------------------------
>  1 file changed, 6 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
> index 9bb263cec6c30..13ccb9e29a2e1 100644
> --- a/drivers/crypto/hisilicon/qm.c
> +++ b/drivers/crypto/hisilicon/qm.c
> @@ -1064,19 +1064,10 @@ static ssize_t qm_cmd_read(struct file *filp, char __user *buffer,
>  	char buf[QM_DBG_READ_LEN];
>  	int len;
>  
> -	if (*pos)
> -		return 0;
> -
> -	if (count < QM_DBG_READ_LEN)
> -		return -ENOSPC;
> +	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n",
> +			"Please echo help to cmd to get help information");
>  
> -	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n",
> -		       "Please echo help to cmd to get help information");
> -
> -	if (copy_to_user(buffer, buf, len))
> -		return -EFAULT;
> -
> -	return (*pos = len);
> +	return simple_read_from_buffer(buffer, count, pos, buf, len);
>  }
>  
>  static void *qm_ctx_alloc(struct hisi_qm *qm, size_t ctx_size,
> @@ -2691,24 +2682,12 @@ static ssize_t qm_status_read(struct file *filp, char __user *buffer,
>  {
>  	struct hisi_qm *qm = filp->private_data;
>  	char buf[QM_DBG_READ_LEN];
> -	int val, cp_len, len;
> -
> -	if (*pos)
> -		return 0;
> -
> -	if (count < QM_DBG_READ_LEN)
> -		return -ENOSPC;
> +	int val, len;
>  
>  	val = atomic_read(&qm->status.flags);
> -	len = snprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
> -	if (!len)
> -		return -EFAULT;
> -
> -	cp_len = copy_to_user(buffer, buf, len);
> -	if (cp_len)
> -		return -EFAULT;
> +	len = scnprintf(buf, QM_DBG_READ_LEN, "%s\n", qm_s[val]);
>  
> -	return (*pos = len);
> +	return simple_read_from_buffer(buffer, count, pos, buf, len);
>  }
>  
>  static const struct file_operations qm_status_fops = {
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] crypto: hisilicon - allow smaller reads in debugfs
  2020-06-05  1:19 ` Shukun Tan
@ 2020-06-05  9:13   ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2020-06-05  9:13 UTC (permalink / raw)
  To: Shukun Tan
  Cc: b6da310b-e633-9f74-f7af-7791d803aaf5, Zhou Wang, Herbert Xu,
	David S. Miller, linux-crypto, linux-kernel, kernel-janitors

On Fri, Jun 05, 2020 at 09:19:53AM +0800, Shukun Tan wrote:
> Hi Dan,
> 
> On 2020/6/2 21:54, Dan Carpenter wrote:
> > Originally this code rejected any read less than 256 bytes.  There
> > is no need for this artificial limit.  We should just use the normal
> > helper functions to read a string from the kernel.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > v2: Use simple_read_from_buffer().  The v1 was slightly half arsed
> > because I left the original check for:
> > 
> > 	if (*pos)
> > 		return 0;
> > 
> > So it could result in partial reads.  The new code means that if you
> > want to read the buffer one byte at a time, that's fine or if you want
> > to read it in one 256 byte chunk that's also fine.  Plus it deletes 21
> > lines of code and is a lot cleaner.
> > 
> 
> In fact, In our original design, we do not hope the user do the partial reads.
> Thank you for your work, but I still insist on adding this limit.

This not how POSIX filesystems work...  :(  Last time you said that this
literally breaks cat.

This doesn't break anything if the user chooses not to read a single
byte at a time.  That's obviously a crazy way to read a file.  It just
allows them to if they want.  Or if they want to read 256 bytes at a
time then that also works.  My patch makes *everything* work.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] crypto: hisilicon - allow smaller reads in debugfs
  2020-06-02 13:54 [PATCH v2] crypto: hisilicon - allow smaller reads in debugfs Dan Carpenter
  2020-06-05  1:19 ` Shukun Tan
@ 2020-06-18  7:56 ` Herbert Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2020-06-18  7:56 UTC (permalink / raw)
  To: b6da310b-e633-9f74-f7af-7791d803aaf5
  Cc: Zhou Wang, Shukun Tan, David S. Miller, linux-crypto,
	linux-kernel, kernel-janitors

On Tue, Jun 02, 2020 at 04:54:09PM +0300, Dan Carpenter wrote:
> Originally this code rejected any read less than 256 bytes.  There
> is no need for this artificial limit.  We should just use the normal
> helper functions to read a string from the kernel.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> v2: Use simple_read_from_buffer().  The v1 was slightly half arsed
> because I left the original check for:
> 
> 	if (*pos)
> 		return 0;
> 
> So it could result in partial reads.  The new code means that if you
> want to read the buffer one byte at a time, that's fine or if you want
> to read it in one 256 byte chunk that's also fine.  Plus it deletes 21
> lines of code and is a lot cleaner.
> 
>  drivers/crypto/hisilicon/qm.c | 33 ++++++---------------------------
>  1 file changed, 6 insertions(+), 27 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-06-18  7:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02 13:54 [PATCH v2] crypto: hisilicon - allow smaller reads in debugfs Dan Carpenter
2020-06-05  1:19 ` Shukun Tan
2020-06-05  9:13   ` Dan Carpenter
2020-06-18  7:56 ` Herbert Xu

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).