Skip to content

Commit

Permalink
dmaengine: idxd: remove trailing white space on input str for wq name
Browse files Browse the repository at this point in the history
Add string processing with strim() in order to remove trailing white spaces
that may be input by user for the wq->name.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/164789525123.2799661.13795829125221129132.stgit@djiang5-desk3.ch.intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
  • Loading branch information
Dave Jiang authored and Vinod Koul committed Apr 11, 2022
1 parent 1f85453 commit 81f5eb2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/dma/idxd/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ static ssize_t wq_name_store(struct device *dev,
size_t count)
{
struct idxd_wq *wq = confdev_to_wq(dev);
char *input, *pos;

if (wq->state != IDXD_WQ_DISABLED)
return -EPERM;
Expand All @@ -846,9 +847,14 @@ static ssize_t wq_name_store(struct device *dev,
if (wq->type == IDXD_WQT_KERNEL && device_pasid_enabled(wq->idxd))
return -EOPNOTSUPP;

input = kstrndup(buf, count, GFP_KERNEL);
if (!input)
return -ENOMEM;

pos = strim(input);
memset(wq->name, 0, WQ_NAME_SIZE + 1);
strncpy(wq->name, buf, WQ_NAME_SIZE);
strreplace(wq->name, '\n', '\0');
sprintf(wq->name, "%s", pos);
kfree(input);
return count;
}

Expand Down

0 comments on commit 81f5eb2

Please sign in to comment.