Skip to contentSkip to conversation

Fix some formatting problems

PATCH In review Miko Larsson 3 participants 8 messages Dec 17, 2021 – Dec 24, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Fix some formatting problems

Hi,

This is v2 of the patch set I sent in two days ago. The subject is arguably misleading, since we're doing a bit more than fixing some "superficial formatting problems", but I wanted to keep the original subject since this is a followup to the previous patch set.

This patch set adds SPDX license identifiers to zram_drv, and replaces all uses of 'strlcpy()' with 'kmemdup_nul()' and 'strcpy()'.

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

 drivers/block/zram/zram_drv.c | 18 ++++++------------
 drivers/block/zram/zram_drv.h |  9 ++-------
 2 files changed, 8 insertions(+), 19 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 zram: zram_drv: add SPDX license identifiers

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

---
 drivers/block/zram/zram_drv.c | 9 ++-------
 drivers/block/zram/zram_drv.h | 9 ++-------
 2 files changed, 4 insertions(+), 14 deletions(-)
drivers/block/zram/zram_drv.c +2 -7
index 25071126995b..4de6fe13edaf 100644
@@ -1,15 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+
 /*
  * Compressed RAM block device
  *
  * Copyright (C) 2008, 2009, 2010  Nitin Gupta
  *               2012, 2013 Minchan Kim
- *
- * This code is released using a dual license strategy: BSD/GPL
- * You can choose the licence that better fits your requirements.
- *
- * Released under the terms of 3-clause BSD License
- * Released under the terms of GNU General Public License Version 2.0
- *
  */
 
 #define KMSG_COMPONENT "zram"
drivers/block/zram/zram_drv.h +2 -7
index 80c3b43b4828..29e75e094a9d 100644
@@ -1,15 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
+
 /*
  * Compressed RAM block device
  *
  * Copyright (C) 2008, 2009, 2010  Nitin Gupta
  *               2012, 2013 Minchan Kim
- *
- * This code is released using a dual license strategy: BSD/GPL
- * You can choose the licence that better fits your requirements.
- *
- * Released under the terms of 3-clause BSD License
- * Released under the terms of GNU General Public License Version 2.0
- *
  */
 
 #ifndef _ZRAM_DRV_H_
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v2 1/2] zram: zram_drv: add SPDX license identifiers

In reply to Miko Larsson

drivers/block/zram/zram_drv.c

Quoted 11 lines · Miko Larsson

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

---
 drivers/block/zram/zram_drv.c | 9 ++-------
 drivers/block/zram/zram_drv.h | 9 ++-------
 2 files changed, 4 insertions(+), 14 deletions(-)
drivers/block/zram/zram_drv.c +0 -0

[]

drivers/block/zram/zram_drv.c line 1

Quoted 2 lines
drivers/block/zram/zram_drv.c +1 -0
@@ -1,15 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause

GPL v2 is a permissive license and this SPDX tag should probably be

// SPDX-License-Identifier: GPL-2.0-or-later or BSD-3-Clause

Quoted 12 lines
drivers/block/zram/zram_drv.c +1 -6
+
 /*
  * Compressed RAM block device
  *
  * Copyright (C) 2008, 2009, 2010  Nitin Gupta
  *               2012, 2013 Minchan Kim
- *
- * This code is released using a dual license strategy: BSD/GPL
- * You can choose the licence that better fits your requirements.
- *
- * Released under the terms of 3-clause BSD License
- * Released under the terms of GNU General Public License Version 2.0
#4 lore raw

Re: [PATCH v2 1/2] zram: zram_drv: add SPDX license identifiers

Quoted 3 lines · Joe Perches

GPL v2 is a permissive license and this SPDX tag should probably be

// SPDX-License-Identifier: GPL-2.0-or-later or BSD-3-Clause

It shouldn't be GPL-2.0-or-later, because the original copyright notice doesn't have an "or later" clause.

#5 lore raw

Re: [PATCH v2 1/2] zram: zram_drv: add SPDX license identifiers

(resending, original sent with an html part, unknown how)

Quoted 7 lines · Miko Larsson
Quoted 3 lines · Joe Perches

GPL v2 is a permissive license and this SPDX tag should probably be

// SPDX-License-Identifier: GPL-2.0-or-later or BSD-3-Clause

It shouldn't be GPL-2.0-or-later, because the original copyright notice doesn't have an "or later" clause.

On its face, a GPL-2.0 license notice grant does _not_ need to include any 'or later' content.

The GPL 2.0 license is permissive, it's at the _grantee's_ option.

I believe Nitin Gupta, the original author and submitter, should declare whether or not he intended the license to include the 'or later' option.

Nitin?

Did you intend to use GPL-2.0 only and exclude GPL-3.0 or any later version?

#6 lore raw

PATCH v2 2/2 zram: zram_drv: replace 'strlcpy()'

In reply to Miko Larsson

'strlcpy()' shouldn't be used, and should be replaced with safer alternatives. Cristoph Hellwig suggested [1] that 'kmemdup_nul()' should be used in two cases instead of 'strscpy()', and that a regular 'strcpy()' should be used in the third case. [2][3]

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/

---
 drivers/block/zram/zram_drv.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/block/zram/zram_drv.c +4 -5
index 4de6fe13edaf..c7c751e6ca2e 100644
@@ -482,7 +482,7 @@ static ssize_t backing_dev_store(struct device *dev,
 	int err;
 	struct zram *zram = dev_to_zram(dev);
 
-	file_name = kmalloc(PATH_MAX, GFP_KERNEL);
+	file_name = kmemdup_nul(buf, PATH_MAX, GFP_KERNEL);
 	if (!file_name)
 		return -ENOMEM;
 
@@ -493,7 +493,6 @@ static ssize_t backing_dev_store(struct device *dev,
 		goto out;
 	}
 
-	strlcpy(file_name, buf, PATH_MAX);
 	/* ignore trailing newline */
 	sz = strlen(file_name);
 	if (sz > 0 && file_name[sz - 1] == '\n')
@@ -1024,10 +1023,10 @@ static ssize_t comp_algorithm_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t len)
 {
 	struct zram *zram = dev_to_zram(dev);
-	char compressor[ARRAY_SIZE(zram->compressor)];
+	char *compressor;
 	size_t sz;
 
-	strlcpy(compressor, buf, sizeof(compressor));
+	compressor = kmemdup_nul(buf, sizeof(zram->compressor), GFP_KERNEL);
 	/* ignore trailing newline */
 	sz = strlen(compressor);
 	if (sz > 0 && compressor[sz - 1] == '\n')
@@ -1981,7 +1980,7 @@ static int zram_add(void)
 	if (ret)
 		goto out_cleanup_disk;
 
-	strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor));
+	strcpy(zram->compressor, default_compressor);
 
 	zram_debugfs_register(zram);
 	pr_info("Added device: %s\n", zram->disk->disk_name);
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#7 lore raw

Re: [PATCH v2 2/2] zram: zram_drv: replace 'strlcpy()'

Quoted 4 lines · Miko Larsson

'strlcpy()' shouldn't be used, and should be replaced with safer alternatives. Cristoph Hellwig suggested [1] that 'kmemdup_nul()' should be used in two cases instead of 'strscpy()', and that a regular 'strcpy()' should be used in the third case. [2][3]

Not that strcpy isn't really safer, but if your plan is to get rid of strlcpy I think it makes more sense there.