linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] zram: zram_drv: Fix some formatting problems
@ 2021-12-15 19:21 Miko Larsson
  2021-12-15 19:21 ` [PATCH 1/2] zram: zram_drv: add SPDX license identifiers Miko Larsson
  2021-12-15 19:21 ` [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy Miko Larsson
  0 siblings, 2 replies; 8+ messages in thread
From: Miko Larsson @ 2021-12-15 19:21 UTC (permalink / raw)
  To: minchan, ngupta, senozhatsky, axboe, linux-kernel, linux-block
  Cc: Miko Larsson

Hi,

This small patch set fixes some superficial formatting problems in
zram_drv that were reported by checkpatch, namely that it missed SPDX
license identifiers and that it used strlcopy instead of strscpy.

Miko Larsson (2):
  zram: zram_drv: add SPDX license identifiers
  zram: zram_drv: replace strlcpy with strscpy

 drivers/block/zram/zram_drv.c | 8 +++++---
 drivers/block/zram/zram_drv.h | 2 ++
 2 files changed, 7 insertions(+), 3 deletions(-)

-- 
2.34.1


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

* [PATCH 1/2] zram: zram_drv: add SPDX license identifiers
  2021-12-15 19:21 [PATCH 0/2] zram: zram_drv: Fix some formatting problems Miko Larsson
@ 2021-12-15 19:21 ` Miko Larsson
  2021-12-16 10:12   ` Christoph Hellwig
  2021-12-15 19:21 ` [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy Miko Larsson
  1 sibling, 1 reply; 8+ messages in thread
From: Miko Larsson @ 2021-12-15 19:21 UTC (permalink / raw)
  To: minchan, ngupta, senozhatsky, axboe, linux-kernel, linux-block
  Cc: Miko Larsson

zram_drv lacks an SPDX license identifier in both its source and in its
header, so we should add a license identifiers based on the copyright
info provided by the initial comment block.

Signed-off-by: Miko Larsson <mikoxyzzz@gmail.com>
---
 drivers/block/zram/zram_drv.c | 2 ++
 drivers/block/zram/zram_drv.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 25071126995b..464ef53adcbc 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1,3 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+
 /*
  * Compressed RAM block device
  *
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 80c3b43b4828..fa00bbe434fb 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
+
 /*
  * Compressed RAM block device
  *
-- 
2.34.1


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

* [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy
  2021-12-15 19:21 [PATCH 0/2] zram: zram_drv: Fix some formatting problems Miko Larsson
  2021-12-15 19:21 ` [PATCH 1/2] zram: zram_drv: add SPDX license identifiers Miko Larsson
@ 2021-12-15 19:21 ` Miko Larsson
  2021-12-16 10:14   ` Christoph Hellwig
  1 sibling, 1 reply; 8+ messages in thread
From: Miko Larsson @ 2021-12-15 19:21 UTC (permalink / raw)
  To: minchan, ngupta, senozhatsky, axboe, linux-kernel, linux-block
  Cc: Miko Larsson

strlcpy shouldn't be used; strscpy should be used instead.

Signed-off-by: Miko Larsson <mikoxyzzz@gmail.com>
---
 drivers/block/zram/zram_drv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 464ef53adcbc..b1774d04a6ea 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -500,7 +500,7 @@ static ssize_t backing_dev_store(struct device *dev,
 		goto out;
 	}
 
-	strlcpy(file_name, buf, PATH_MAX);
+	strscpy(file_name, buf, PATH_MAX);
 	/* ignore trailing newline */
 	sz = strlen(file_name);
 	if (sz > 0 && file_name[sz - 1] == '\n')
@@ -1034,7 +1034,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
 	char compressor[ARRAY_SIZE(zram->compressor)];
 	size_t sz;
 
-	strlcpy(compressor, buf, sizeof(compressor));
+	strscpy(compressor, buf, sizeof(compressor));
 	/* ignore trailing newline */
 	sz = strlen(compressor);
 	if (sz > 0 && compressor[sz - 1] == '\n')
@@ -1988,7 +1988,7 @@ static int zram_add(void)
 	if (ret)
 		goto out_cleanup_disk;
 
-	strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
+	strscpy(zram->compressor, default_compressor, sizeof(zram->compressor));
 
 	zram_debugfs_register(zram);
 	pr_info("Added device: %s\n", zram->disk->disk_name);
-- 
2.34.1


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

* Re: [PATCH 1/2] zram: zram_drv: add SPDX license identifiers
  2021-12-15 19:21 ` [PATCH 1/2] zram: zram_drv: add SPDX license identifiers Miko Larsson
@ 2021-12-16 10:12   ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-12-16 10:12 UTC (permalink / raw)
  To: Miko Larsson
  Cc: minchan, ngupta, senozhatsky, axboe, linux-kernel, linux-block

On Wed, Dec 15, 2021 at 08:21:27PM +0100, Miko Larsson wrote:
> zram_drv lacks an SPDX license identifier in both its source and in its
> header, so we should add a license identifiers based on the copyright
> info provided by the initial comment block.
> 
> Signed-off-by: Miko Larsson <mikoxyzzz@gmail.com>
> ---
>  drivers/block/zram/zram_drv.c | 2 ++
>  drivers/block/zram/zram_drv.h | 2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 25071126995b..464ef53adcbc 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -1,3 +1,5 @@
> +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause

Please drop the free form license boilerplate when adding SPDX tags.

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

* Re: [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy
  2021-12-15 19:21 ` [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy Miko Larsson
@ 2021-12-16 10:14   ` Christoph Hellwig
  2021-12-16 15:00     ` Miko Larsson
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-12-16 10:14 UTC (permalink / raw)
  To: Miko Larsson
  Cc: minchan, ngupta, senozhatsky, axboe, linux-kernel, linux-block

On Wed, Dec 15, 2021 at 08:21:28PM +0100, Miko Larsson wrote:
> strlcpy shouldn't be used; strscpy should be used instead.

I think the proper API to use here would be kmemdup_nul.

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

* Re: [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy
  2021-12-16 10:14   ` Christoph Hellwig
@ 2021-12-16 15:00     ` Miko Larsson
  2021-12-16 17:52       ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Miko Larsson @ 2021-12-16 15:00 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: minchan, ngupta, senozhatsky, axboe, linux-kernel, linux-block

On Thu, 16 Dec 2021 02:14:44 -0800
Christoph Hellwig <hch@infradead.org> wrote:

> On Wed, Dec 15, 2021 at 08:21:28PM +0100, Miko Larsson wrote:
> > strlcpy shouldn't be used; strscpy should be used instead.
> 
> I think the proper API to use here would be kmemdup_nul.

Thanks for the heads-up! That only seems to apply to the assignment of
'file_name'. The usage of strscpy seems to be correct in the other two
cases, though (since they're char arrays.) I suspect I might be wrong
though, since my knowledge of C is shabby at best.

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

* Re: [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy
  2021-12-16 15:00     ` Miko Larsson
@ 2021-12-16 17:52       ` Christoph Hellwig
  2021-12-16 17:52         ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2021-12-16 17:52 UTC (permalink / raw)
  To: Miko Larsson
  Cc: Christoph Hellwig, minchan, ngupta, senozhatsky, axboe,
	linux-kernel, linux-block

On Thu, Dec 16, 2021 at 04:00:21PM +0100, Miko Larsson wrote:
> Thanks for the heads-up! That only seems to apply to the assignment of
> 'file_name'. The usage of strscpy seems to be correct in the other two
> cases, though (since they're char arrays.) I suspect I might be wrong
> though, since my knowledge of C is shabby at best.

The second one also sounds like a case for memdup_nul.  That adds a
memory allocation, but it keeps all the checking nicely encapsulated,
and the last one should be fine with a plain old mempcy.

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

* Re: [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy
  2021-12-16 17:52       ` Christoph Hellwig
@ 2021-12-16 17:52         ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-12-16 17:52 UTC (permalink / raw)
  To: Miko Larsson
  Cc: Christoph Hellwig, minchan, ngupta, senozhatsky, axboe,
	linux-kernel, linux-block

On Thu, Dec 16, 2021 at 09:52:01AM -0800, Christoph Hellwig wrote:
> On Thu, Dec 16, 2021 at 04:00:21PM +0100, Miko Larsson wrote:
> > Thanks for the heads-up! That only seems to apply to the assignment of
> > 'file_name'. The usage of strscpy seems to be correct in the other two
> > cases, though (since they're char arrays.) I suspect I might be wrong
> > though, since my knowledge of C is shabby at best.
> 
> The second one also sounds like a case for memdup_nul.  That adds a
> memory allocation, but it keeps all the checking nicely encapsulated,
> and the last one should be fine with a plain old mempcy.

sorry, s/memcpy/strcpy/

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

end of thread, other threads:[~2021-12-16 17:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15 19:21 [PATCH 0/2] zram: zram_drv: Fix some formatting problems Miko Larsson
2021-12-15 19:21 ` [PATCH 1/2] zram: zram_drv: add SPDX license identifiers Miko Larsson
2021-12-16 10:12   ` Christoph Hellwig
2021-12-15 19:21 ` [PATCH 2/2] zram: zram_drv: replace strlcpy with strscpy Miko Larsson
2021-12-16 10:14   ` Christoph Hellwig
2021-12-16 15:00     ` Miko Larsson
2021-12-16 17:52       ` Christoph Hellwig
2021-12-16 17:52         ` Christoph Hellwig

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