Content-Type: multipart/mixed; boundary="===============1501080008660012672==" MIME-Version: 1.0 From: Ramesh Thomas Subject: [Accel-config] Re: [PATCH] accel-config: Fix a read buffer length bug Date: Wed, 02 Feb 2022 17:02:52 -0800 Message-ID: <0c857976-15bd-9d21-1121-038d97d59b9f@intel.com> In-Reply-To: a3a6044f-aed9-7f4d-845b-aa3012ea7736@intel.com To: accel-config@lists.01.org List-ID: --===============1501080008660012672== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On 2/2/2022 3:26 PM, Dave Jiang wrote: > = > On 2/2/2022 3:50 PM, Ramesh Thomas wrote: >> Generic function used to read a string attribute was using a buffer of >> max length 64. Attributes like op_cap exceeds that size. Change read >> buffer length to 128. Also removed a redundant memory allocation. > = > For sysfs attributes, max buffer size is 4k (a page). Probably should = > make all reads from sysfs to be that size? Yes, it should match the driver buffer size. > = > = >> Signed-off-by: Ramesh Thomas >> --- >> =C2=A0 accfg/lib/libaccfg.c | 14 ++------------ >> =C2=A0 1 file changed, 2 insertions(+), 12 deletions(-) >> >> diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c >> index 9cdd8f8..f20706c 100644 >> --- a/accfg/lib/libaccfg.c >> +++ b/accfg/lib/libaccfg.c >> @@ -247,13 +247,13 @@ static uint64_t accfg_get_param_unsigned_llong( >> =C2=A0 static char *accfg_get_param_str(struct accfg_ctx *ctx, int dfd, = >> char *name) >> =C2=A0 { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int fd =3D openat(dfd, name, O_RDONLY); >> -=C2=A0=C2=A0=C2=A0 char buf[MAX_PARAM_LEN + 1]; >> +=C2=A0=C2=A0=C2=A0 char buf[MAX_BUF_LEN + 1]; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int n; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (fd =3D=3D -1) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; >> -=C2=A0=C2=A0=C2=A0 n =3D read(fd, buf, MAX_PARAM_LEN); >> +=C2=A0=C2=A0=C2=A0 n =3D read(fd, buf, MAX_BUF_LEN); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 close(fd); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (n <=3D 0) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; >> @@ -618,21 +618,13 @@ static void *add_device(void *parent, int id, = >> const char *ctl_base, >> =C2=A0 { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct accfg_ctx *ctx =3D parent; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct accfg_device *device; >> -=C2=A0=C2=A0=C2=A0 char *path; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int dfd; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int rc; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 char *p; >> -=C2=A0=C2=A0=C2=A0 path =3D calloc(1, strlen(ctl_base) + MAX_PARAM_LEN); >> -=C2=A0=C2=A0=C2=A0 if (!path) { >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 err(ctx, "%s: allocation of = path failed\n", __func__); >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; >> -=C2=A0=C2=A0=C2=A0 } >> - >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 dfd =3D open(ctl_base, O_PATH); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (dfd =3D=3D -1) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 err(ctx, "%s open= failed: %s\n", __func__, strerror(errno)); >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 free(path); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> @@ -720,7 +712,6 @@ static void *add_device(void *parent, int id, = >> const char *ctl_base, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto err_dev_path; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 list_add_tail(&ctx->devices, &device->lis= t); >> -=C2=A0=C2=A0=C2=A0 free(path); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return device; >> @@ -730,7 +721,6 @@ err_read: >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 free(device->mdev_path); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 free(device); >> =C2=A0 err_device: >> -=C2=A0=C2=A0=C2=A0 free(path); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; >> =C2=A0 } --===============1501080008660012672==--