Skip to content

Commit

Permalink
accel-config: Fix a bug with empty wq driver name
Browse files Browse the repository at this point in the history
Some sysfs string attributes contain a newline character even if empty.
In some cases there are even more than one. Driver name when empty
contained the newline character leading to forming an invalid driver
bind path. Another error was the check for an empty driver_name was
assuming the driver_name field would be NULL if empty.

Trim sysfs string attributes after any newline character. At wq enable,
check for empty driver_name string before creating driver bind path.

Signed-off-by: Ramesh Thomas <[email protected]>
  • Loading branch information
ramesh-thomas committed Sep 1, 2023
1 parent c35c0f1 commit 4f604b5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions accfg/lib/libaccfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,8 @@ static char *accfg_get_param_str(struct accfg_ctx *ctx, int dfd, char *name)
if (n <= 0)
return NULL;

if (buf[n - 1] == '\n')
buf[n - 1] = '\0';
else
buf[n] = '\0';
buf[n] = '\0';
*strchrnul(buf, '\n') = '\0';

return strdup(buf);
}
Expand Down Expand Up @@ -2079,7 +2077,8 @@ static int accfg_wq_control(struct accfg_wq *wq, enum accfg_control_flag flag,

if (flag == ACCFG_WQ_ENABLE) {
rc = get_driver_bind_path(device->bus_type_str,
wq->driver_name ? wq->driver_name :
wq->driver_name && strlen(wq->driver_name) ?
wq->driver_name :
IDXD_WQ_DEVICE_PORTAL(device, wq), &path);
if (rc < 0)
return rc;
Expand Down

0 comments on commit 4f604b5

Please sign in to comment.