diff mbox series

[07/12] block: use kstrtoul in flag_store

Message ID 20240605063031.3286655-8-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [01/12] dm-integrity: use the nop integrity profile | expand

Commit Message

Christoph Hellwig June 5, 2024, 6:28 a.m. UTC
Use the text to integer helper that has error handling and doesn't modify
the input pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-integrity.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Keith Busch June 5, 2024, 4 p.m. UTC | #1
On Wed, Jun 05, 2024 at 08:28:36AM +0200, Christoph Hellwig wrote:
> Use the text to integer helper that has error handling and doesn't modify
> the input pointer.

Looks good. 

Reviewed-by: Keith Busch <kbusch@kernel.org>
Chaitanya Kulkarni June 6, 2024, 12:16 a.m. UTC | #2
On 6/4/2024 11:28 PM, Christoph Hellwig wrote:
> Use the text to integer helper that has error handling and doesn't modify
> the input pointer.
> 
> Signed-off-by: Christoph Hellwig<hch@lst.de>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
diff mbox series

Patch

diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 686b6adf0ea5c7..bb3cd1e0eeb58e 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -245,8 +245,12 @@  static ssize_t flag_store(struct device *dev, struct device_attribute *attr,
 		const char *page, size_t count, unsigned char flag)
 {
 	struct blk_integrity *bi = dev_to_bi(dev);
-	char *p = (char *) page;
-	unsigned long val = simple_strtoul(p, &p, 10);
+	unsigned long val;
+	int err;
+
+	err = kstrtoul(page, 10, &val);
+	if (err)
+		return err;
 
 	if (val)
 		bi->flags |= flag;