* [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 [not found] <20260526061321.6123-1-grandmaster@al2klimov.de> @ 2026-05-26 6:13 ` Alexander A. Klimov 2026-05-26 6:24 ` sashiko-bot 2026-05-26 14:49 ` Dave Jiang 0 siblings, 2 replies; 6+ messages in thread From: Alexander A. Klimov @ 2026-05-26 6:13 UTC (permalink / raw) To: Vinod Koul, Frank Li, Thomas Weißschuh, Dave Jiang, Alexander A. Klimov, Ujjal Singh, open list:DMA GENERIC OFFLOAD ENGINE SUBSYSTEM, open list Depending on the user input, sscanf() may return 0 for 0 success. But intr_coalesce_store() wants sscanf() to parse one number, so expect 1 from sscanf(), not any int except -1. While on it, fix typo in %du by using just %d, as this interface expects %d or %d\n. Latter made scripts/checkpatch.pl complain, so use kstrtoint() instead of sscanf(). Fixes: 268e2519f5b7 ("dmaengine: ioatdma: Add intr_coalesce sysfs entry") Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de> --- drivers/dma/ioat/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/ioat/sysfs.c b/drivers/dma/ioat/sysfs.c index e796ddb5383f..f59df569956a 100644 --- a/drivers/dma/ioat/sysfs.c +++ b/drivers/dma/ioat/sysfs.c @@ -144,7 +144,7 @@ size_t count) int intr_coalesce = 0; struct ioatdma_chan *ioat_chan = to_ioat_chan(c); - if (sscanf(page, "%du", &intr_coalesce) != -1) { + if (!kstrtoint(page, 10, &intr_coalesce)) { if ((intr_coalesce < 0) || (intr_coalesce > IOAT_INTRDELAY_MASK)) return -EINVAL; -- 2.54.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 2026-05-26 6:13 ` [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 Alexander A. Klimov @ 2026-05-26 6:24 ` sashiko-bot 2026-05-26 14:49 ` Dave Jiang 1 sibling, 0 replies; 6+ messages in thread From: sashiko-bot @ 2026-05-26 6:24 UTC (permalink / raw) To: Alexander A. Klimov; +Cc: vkoul, Frank.Li, dmaengine Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The sysfs store function silently ignores parsing errors and incorrectly returns success (`count`) when given invalid input. -- commit fe01246cf60369a73aac5e63b92278079b4417aa Author: Alexander A. Klimov <grandmaster@al2klimov.de> dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 The commit replaces the use of sscanf() with kstrtoint() in the sysfs store function to parse user input. It also addresses a checkpatch.pl warning regarding the formatting string. > diff --git a/drivers/dma/ioat/sysfs.c b/drivers/dma/ioat/sysfs.c > index e796ddb5383f8..f59df569956ae 100644 > --- a/drivers/dma/ioat/sysfs.c > +++ b/drivers/dma/ioat/sysfs.c > @@ -144,7 +144,7 @@ size_t count) > int intr_coalesce = 0; > struct ioatdma_chan *ioat_chan = to_ioat_chan(c); > > - if (sscanf(page, "%du", &intr_coalesce) != -1) { > + if (!kstrtoint(page, 10, &intr_coalesce)) { > if ((intr_coalesce < 0) || > (intr_coalesce > IOAT_INTRDELAY_MASK)) > return -EINVAL; [Severity: Medium] If kstrtoint() fails to parse the input and returns a negative error code, the condition evaluates to false and the function skips the block. Looking at the remainder of intr_coalesce_store(), execution then jumps directly to the end of the function: if (!kstrtoint(page, 10, &intr_coalesce)) { ... ioat_chan->intr_coalesce = intr_coalesce; } return count; Does this silently ignore parsing errors and incorrectly indicate to userspace that the write was successful when given invalid input? -- Sashiko AI review · https://sashiko.dev/#/patchset/20260526061321.6123-3-grandmaster@al2klimov.de?part=1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 2026-05-26 6:13 ` [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 Alexander A. Klimov 2026-05-26 6:24 ` sashiko-bot @ 2026-05-26 14:49 ` Dave Jiang 2026-05-26 18:06 ` Alexander A. Klimov 1 sibling, 1 reply; 6+ messages in thread From: Dave Jiang @ 2026-05-26 14:49 UTC (permalink / raw) To: Alexander A. Klimov, Vinod Koul, Frank Li, Thomas Weißschuh, Ujjal Singh, open list:DMA GENERIC OFFLOAD ENGINE SUBSYSTEM, open list On 5/25/26 11:13 PM, Alexander A. Klimov wrote: > Depending on the user input, sscanf() may return 0 for 0 success. > But intr_coalesce_store() wants sscanf() to parse one number, > so expect 1 from sscanf(), not any int except -1. > > While on it, fix typo in %du by using just %d, > as this interface expects %d or %d\n. > Latter made scripts/checkpatch.pl complain, > so use kstrtoint() instead of sscanf(). > > Fixes: 268e2519f5b7 ("dmaengine: ioatdma: Add intr_coalesce sysfs entry") > Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de> > --- > drivers/dma/ioat/sysfs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/dma/ioat/sysfs.c b/drivers/dma/ioat/sysfs.c > index e796ddb5383f..f59df569956a 100644 > --- a/drivers/dma/ioat/sysfs.c > +++ b/drivers/dma/ioat/sysfs.c > @@ -144,7 +144,7 @@ size_t count) > int intr_coalesce = 0; > struct ioatdma_chan *ioat_chan = to_ioat_chan(c); > > - if (sscanf(page, "%du", &intr_coalesce) != -1) { > + if (!kstrtoint(page, 10, &intr_coalesce)) { looks good. We can probably use kstrtouint() since we are expecting a positive number always. DJ > if ((intr_coalesce < 0) || > (intr_coalesce > IOAT_INTRDELAY_MASK)) > return -EINVAL; ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 2026-05-26 14:49 ` Dave Jiang @ 2026-05-26 18:06 ` Alexander A. Klimov 2026-05-28 20:06 ` Dave Jiang 0 siblings, 1 reply; 6+ messages in thread From: Alexander A. Klimov @ 2026-05-26 18:06 UTC (permalink / raw) To: Dave Jiang, Vinod Koul, Frank Li, Thomas Weißschuh, Ujjal Singh, open list:DMA GENERIC OFFLOAD ENGINE SUBSYSTEM, open list On 5/26/26 16:49, Dave Jiang wrote: > > > On 5/25/26 11:13 PM, Alexander A. Klimov wrote: >> Depending on the user input, sscanf() may return 0 for 0 success. >> But intr_coalesce_store() wants sscanf() to parse one number, >> so expect 1 from sscanf(), not any int except -1. >> >> While on it, fix typo in %du by using just %d, >> as this interface expects %d or %d\n. >> Latter made scripts/checkpatch.pl complain, >> so use kstrtoint() instead of sscanf(). >> >> Fixes: 268e2519f5b7 ("dmaengine: ioatdma: Add intr_coalesce sysfs entry") >> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de> >> --- >> drivers/dma/ioat/sysfs.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/dma/ioat/sysfs.c b/drivers/dma/ioat/sysfs.c >> index e796ddb5383f..f59df569956a 100644 >> --- a/drivers/dma/ioat/sysfs.c >> +++ b/drivers/dma/ioat/sysfs.c >> @@ -144,7 +144,7 @@ size_t count) >> int intr_coalesce = 0; >> struct ioatdma_chan *ioat_chan = to_ioat_chan(c); >> >> - if (sscanf(page, "%du", &intr_coalesce) != -1) { >> + if (!kstrtoint(page, 10, &intr_coalesce)) { > > looks good. We can probably use kstrtouint() since we are expecting a positive number always. This would break `return -EINVAL;` below > > DJ > >> if ((intr_coalesce < 0) || >> (intr_coalesce > IOAT_INTRDELAY_MASK)) >> return -EINVAL; > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 2026-05-26 18:06 ` Alexander A. Klimov @ 2026-05-28 20:06 ` Dave Jiang [not found] ` <ef38b0e8-2b6f-4f65-bac5-177b981479ae@al2klimov.de> 0 siblings, 1 reply; 6+ messages in thread From: Dave Jiang @ 2026-05-28 20:06 UTC (permalink / raw) To: Alexander A. Klimov, Vinod Koul, Frank Li, Thomas Weißschuh, Ujjal Singh, open list:DMA GENERIC OFFLOAD ENGINE SUBSYSTEM, open list On 5/26/26 11:06 AM, Alexander A. Klimov wrote: > > > On 5/26/26 16:49, Dave Jiang wrote: >> >> >> On 5/25/26 11:13 PM, Alexander A. Klimov wrote: >>> Depending on the user input, sscanf() may return 0 for 0 success. >>> But intr_coalesce_store() wants sscanf() to parse one number, >>> so expect 1 from sscanf(), not any int except -1. >>> >>> While on it, fix typo in %du by using just %d, >>> as this interface expects %d or %d\n. >>> Latter made scripts/checkpatch.pl complain, >>> so use kstrtoint() instead of sscanf(). >>> >>> Fixes: 268e2519f5b7 ("dmaengine: ioatdma: Add intr_coalesce sysfs entry") >>> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de> >>> --- >>> drivers/dma/ioat/sysfs.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>> >>> diff --git a/drivers/dma/ioat/sysfs.c b/drivers/dma/ioat/sysfs.c >>> index e796ddb5383f..f59df569956a 100644 >>> --- a/drivers/dma/ioat/sysfs.c >>> +++ b/drivers/dma/ioat/sysfs.c >>> @@ -144,7 +144,7 @@ size_t count) >>> int intr_coalesce = 0; >>> struct ioatdma_chan *ioat_chan = to_ioat_chan(c); >>> - if (sscanf(page, "%du", &intr_coalesce) != -1) { >>> + if (!kstrtoint(page, 10, &intr_coalesce)) { >> >> looks good. We can probably use kstrtouint() since we are expecting a positive number always. > > This would break `return -EINVAL;` below Shouldn't we just drop the < 0 compare since it's no longer needed? > >> >> DJ >> >>> if ((intr_coalesce < 0) || >>> (intr_coalesce > IOAT_INTRDELAY_MASK)) >>> return -EINVAL; >> > ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <ef38b0e8-2b6f-4f65-bac5-177b981479ae@al2klimov.de>]
* Re: [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 [not found] ` <ef38b0e8-2b6f-4f65-bac5-177b981479ae@al2klimov.de> @ 2026-06-01 15:12 ` Dave Jiang 0 siblings, 0 replies; 6+ messages in thread From: Dave Jiang @ 2026-06-01 15:12 UTC (permalink / raw) To: Alexander A. Klimov, Vinod Koul, Frank Li, Thomas Weißschuh, Ujjal Singh, open list:DMA GENERIC OFFLOAD ENGINE SUBSYSTEM, open list On 5/31/26 1:56 AM, Alexander A. Klimov wrote: > > > On 5/28/26 22:06, Dave Jiang wrote: >> >> >> On 5/26/26 11:06 AM, Alexander A. Klimov wrote: >>> >>> >>> On 5/26/26 16:49, Dave Jiang wrote: >>>> >>>> >>>> On 5/25/26 11:13 PM, Alexander A. Klimov wrote: >>>>> Depending on the user input, sscanf() may return 0 for 0 success. >>>>> But intr_coalesce_store() wants sscanf() to parse one number, >>>>> so expect 1 from sscanf(), not any int except -1. >>>>> >>>>> While on it, fix typo in %du by using just %d, >>>>> as this interface expects %d or %d\n. >>>>> Latter made scripts/checkpatch.pl complain, >>>>> so use kstrtoint() instead of sscanf(). >>>>> >>>>> Fixes: 268e2519f5b7 ("dmaengine: ioatdma: Add intr_coalesce sysfs entry") >>>>> Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de> >>>>> --- >>>>> drivers/dma/ioat/sysfs.c | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>> >>>>> diff --git a/drivers/dma/ioat/sysfs.c b/drivers/dma/ioat/sysfs.c >>>>> index e796ddb5383f..f59df569956a 100644 >>>>> --- a/drivers/dma/ioat/sysfs.c >>>>> +++ b/drivers/dma/ioat/sysfs.c >>>>> @@ -144,7 +144,7 @@ size_t count) >>>>> int intr_coalesce = 0; >>>>> struct ioatdma_chan *ioat_chan = to_ioat_chan(c); >>>>> - if (sscanf(page, "%du", &intr_coalesce) != -1) { >>>>> + if (!kstrtoint(page, 10, &intr_coalesce)) { >>>> >>>> looks good. We can probably use kstrtouint() since we are expecting a positive number always. >>> >>> This would break `return -EINVAL;` below >> >> Shouldn't we just drop the < 0 compare since it's no longer needed? > > Wouldn't that change behavior shown to userspace from return -EINVAL > on negative int input to return count? No a negative value would trigger parsing error and return -EINVAL. Same behavior for user. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-01 15:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260526061321.6123-1-grandmaster@al2klimov.de>
2026-05-26 6:13 ` [PATCH] dmaengine: ioatdma: use !kstrtoint(), not sscanf()!=-1 Alexander A. Klimov
2026-05-26 6:24 ` sashiko-bot
2026-05-26 14:49 ` Dave Jiang
2026-05-26 18:06 ` Alexander A. Klimov
2026-05-28 20:06 ` Dave Jiang
[not found] ` <ef38b0e8-2b6f-4f65-bac5-177b981479ae@al2klimov.de>
2026-06-01 15:12 ` Dave Jiang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox