All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
@ 2017-08-03 16:33 ` Matthias Kaehlcke
  0 siblings, 0 replies; 8+ messages in thread
From: Matthias Kaehlcke @ 2017-08-03 16:33 UTC (permalink / raw)
  To: Minchan Kim, Nitin Gupta, Sergey Senozhatsky
  Cc: linux-kernel, linux-mm, Doug Anderson, Nick Desaulniers,
	Matthias Kaehlcke

comp_algorithm_store() passes the size of the source buffer to strlcpy()
instead of the destination buffer size. Make it explicit that the two
buffers have the same size and use strcpy() instead of strlcpy().
The latter can be done safely since the function ensures that the string
in the source buffer is terminated.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in v2:
- make destination buffer explicitly of the same size as source buffer
- use strcpy() instead of strlcpy()
- updated subject and commit message

 drivers/block/zram/zram_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 856d5dc02451..3b1b6340ba13 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -308,7 +308,7 @@ 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[CRYPTO_MAX_ALG_NAME];
+	char compressor[ARRAY_SIZE(zram->compressor)];
 	size_t sz;
 
 	strlcpy(compressor, buf, sizeof(compressor));
@@ -327,7 +327,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
 		return -EBUSY;
 	}
 
-	strlcpy(zram->compressor, compressor, sizeof(compressor));
+	strcpy(zram->compressor, compressor);
 	up_write(&zram->init_lock);
 	return len;
 }
-- 
2.14.0.rc1.383.gd1ce394fe2-goog

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

* [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
@ 2017-08-03 16:33 ` Matthias Kaehlcke
  0 siblings, 0 replies; 8+ messages in thread
From: Matthias Kaehlcke @ 2017-08-03 16:33 UTC (permalink / raw)
  To: Minchan Kim, Nitin Gupta, Sergey Senozhatsky
  Cc: linux-kernel, linux-mm, Doug Anderson, Nick Desaulniers,
	Matthias Kaehlcke

comp_algorithm_store() passes the size of the source buffer to strlcpy()
instead of the destination buffer size. Make it explicit that the two
buffers have the same size and use strcpy() instead of strlcpy().
The latter can be done safely since the function ensures that the string
in the source buffer is terminated.

Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
---
Changes in v2:
- make destination buffer explicitly of the same size as source buffer
- use strcpy() instead of strlcpy()
- updated subject and commit message

 drivers/block/zram/zram_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 856d5dc02451..3b1b6340ba13 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -308,7 +308,7 @@ 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[CRYPTO_MAX_ALG_NAME];
+	char compressor[ARRAY_SIZE(zram->compressor)];
 	size_t sz;
 
 	strlcpy(compressor, buf, sizeof(compressor));
@@ -327,7 +327,7 @@ static ssize_t comp_algorithm_store(struct device *dev,
 		return -EBUSY;
 	}
 
-	strlcpy(zram->compressor, compressor, sizeof(compressor));
+	strcpy(zram->compressor, compressor);
 	up_write(&zram->init_lock);
 	return len;
 }
-- 
2.14.0.rc1.383.gd1ce394fe2-goog

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
  2017-08-03 16:33 ` Matthias Kaehlcke
@ 2017-08-03 16:39   ` Doug Anderson
  -1 siblings, 0 replies; 8+ messages in thread
From: Doug Anderson @ 2017-08-03 16:39 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Minchan Kim, Nitin Gupta, Sergey Senozhatsky, linux-kernel,
	linux-mm, Nick Desaulniers

Hi,

On Thu, Aug 3, 2017 at 9:33 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
> comp_algorithm_store() passes the size of the source buffer to strlcpy()
> instead of the destination buffer size. Make it explicit that the two
> buffers have the same size and use strcpy() instead of strlcpy().
> The latter can be done safely since the function ensures that the string
> in the source buffer is terminated.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> Changes in v2:
> - make destination buffer explicitly of the same size as source buffer
> - use strcpy() instead of strlcpy()
> - updated subject and commit message
>
>  drivers/block/zram/zram_drv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Looks great.  Commit message could be explicit that this change fixes
no bugs and is mostly a no-op (strcpy may be slightly faster than
strlcpy), but I guess that's obvious to anyone looking at the patch.

Reviewed-by: Douglas Anderson <dianders@chromium.org>

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

* Re: [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
@ 2017-08-03 16:39   ` Doug Anderson
  0 siblings, 0 replies; 8+ messages in thread
From: Doug Anderson @ 2017-08-03 16:39 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Minchan Kim, Nitin Gupta, Sergey Senozhatsky, linux-kernel,
	linux-mm, Nick Desaulniers

Hi,

On Thu, Aug 3, 2017 at 9:33 AM, Matthias Kaehlcke <mka@chromium.org> wrote:
> comp_algorithm_store() passes the size of the source buffer to strlcpy()
> instead of the destination buffer size. Make it explicit that the two
> buffers have the same size and use strcpy() instead of strlcpy().
> The latter can be done safely since the function ensures that the string
> in the source buffer is terminated.
>
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
> Changes in v2:
> - make destination buffer explicitly of the same size as source buffer
> - use strcpy() instead of strlcpy()
> - updated subject and commit message
>
>  drivers/block/zram/zram_drv.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Looks great.  Commit message could be explicit that this change fixes
no bugs and is mostly a no-op (strcpy may be slightly faster than
strlcpy), but I guess that's obvious to anyone looking at the patch.

Reviewed-by: Douglas Anderson <dianders@chromium.org>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
  2017-08-03 16:33 ` Matthias Kaehlcke
@ 2017-08-04  1:05   ` Sergey Senozhatsky
  -1 siblings, 0 replies; 8+ messages in thread
From: Sergey Senozhatsky @ 2017-08-04  1:05 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Minchan Kim, Nitin Gupta, Sergey Senozhatsky, linux-kernel,
	linux-mm, Doug Anderson, Nick Desaulniers

On (08/03/17 09:33), Matthias Kaehlcke wrote:
> comp_algorithm_store() passes the size of the source buffer to strlcpy()
> instead of the destination buffer size. Make it explicit that the two
> buffers have the same size and use strcpy() instead of strlcpy().
> The latter can be done safely since the function ensures that the string
> in the source buffer is terminated.
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>

Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

	-ss

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

* Re: [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
@ 2017-08-04  1:05   ` Sergey Senozhatsky
  0 siblings, 0 replies; 8+ messages in thread
From: Sergey Senozhatsky @ 2017-08-04  1:05 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Minchan Kim, Nitin Gupta, Sergey Senozhatsky, linux-kernel,
	linux-mm, Doug Anderson, Nick Desaulniers

On (08/03/17 09:33), Matthias Kaehlcke wrote:
> comp_algorithm_store() passes the size of the source buffer to strlcpy()
> instead of the destination buffer size. Make it explicit that the two
> buffers have the same size and use strcpy() instead of strlcpy().
> The latter can be done safely since the function ensures that the string
> in the source buffer is terminated.
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>

Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

	-ss

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
  2017-08-03 16:33 ` Matthias Kaehlcke
@ 2017-08-04  1:11   ` Minchan Kim
  -1 siblings, 0 replies; 8+ messages in thread
From: Minchan Kim @ 2017-08-04  1:11 UTC (permalink / raw)
  To: Matthias Kaehlcke, Andrew Morton
  Cc: Nitin Gupta, Sergey Senozhatsky, linux-kernel, linux-mm,
	Doug Anderson, Nick Desaulniers

On Thu, Aug 03, 2017 at 09:33:50AM -0700, Matthias Kaehlcke wrote:
> comp_algorithm_store() passes the size of the source buffer to strlcpy()
> instead of the destination buffer size. Make it explicit that the two
> buffers have the same size and use strcpy() instead of strlcpy().
> The latter can be done safely since the function ensures that the string
> in the source buffer is terminated.
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Acked-by: Minchan Kim <minchan@kernel.org>

Thanks.

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

* Re: [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store()
@ 2017-08-04  1:11   ` Minchan Kim
  0 siblings, 0 replies; 8+ messages in thread
From: Minchan Kim @ 2017-08-04  1:11 UTC (permalink / raw)
  To: Matthias Kaehlcke, Andrew Morton
  Cc: Nitin Gupta, Sergey Senozhatsky, linux-kernel, linux-mm,
	Doug Anderson, Nick Desaulniers

On Thu, Aug 03, 2017 at 09:33:50AM -0700, Matthias Kaehlcke wrote:
> comp_algorithm_store() passes the size of the source buffer to strlcpy()
> instead of the destination buffer size. Make it explicit that the two
> buffers have the same size and use strcpy() instead of strlcpy().
> The latter can be done safely since the function ensures that the string
> in the source buffer is terminated.
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Acked-by: Minchan Kim <minchan@kernel.org>

Thanks.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2017-08-04  1:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-03 16:33 [PATCH v2] zram: Rework copy of compressor name in comp_algorithm_store() Matthias Kaehlcke
2017-08-03 16:33 ` Matthias Kaehlcke
2017-08-03 16:39 ` Doug Anderson
2017-08-03 16:39   ` Doug Anderson
2017-08-04  1:05 ` Sergey Senozhatsky
2017-08-04  1:05   ` Sergey Senozhatsky
2017-08-04  1:11 ` Minchan Kim
2017-08-04  1:11   ` Minchan Kim

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.