zram: Rework copy of compressor name in comp_algorithm_store()
Subsystems (3)
PATCH v2 1/1 zram: Rework copy of compressor name in comp_algorithm_store()
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.
---
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(-)
drivers/block/zram/zram_drv.c +2 -2
@@ -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; }
Signature · 7 lines
2.14.0.rc1.383.gd1ce394fe2-goog -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi,
Quoted 7 lines · Matthias Kaehlcke
comp_algorithm_store()passes the size of the source buffer tostrlcpy()instead of the destination buffer size. Make it explicit that the two buffers have the same size and usestrcpy()instead ofstrlcpy(). The latter can be done safely since the function ensures that the string in the source buffer is terminated.Signed-off-by Matthias Kaehlcke <[email protected]>
Quoted 8 lines
---
Changes in v2:
- make destination buffer explicitly of the same size as source buffer
- usestrcpy()instead ofstrlcpy()
- updated subject and commit messagedrivers/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.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Matthias Kaehlcke
comp_algorithm_store()passes the size of the source buffer tostrlcpy()instead of the destination buffer size. Make it explicit that the two buffers have the same size and usestrcpy()instead ofstrlcpy(). The latter can be done safely since the function ensures that the string in the source buffer is terminated.Signed-off-by Matthias Kaehlcke <[email protected]>
-ss
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Matthias Kaehlcke
comp_algorithm_store()passes the size of the source buffer tostrlcpy()instead of the destination buffer size. Make it explicit that the two buffers have the same size and usestrcpy()instead ofstrlcpy(). The latter can be done safely since the function ensures that the string in the source buffer is terminated.Signed-off-by Matthias Kaehlcke <[email protected]>
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>