All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramesh Thomas <ramesh.thomas at intel.com>
To: accel-config@lists.01.org
Subject: [Accel-config] [PATCH] accel-config: Fix a read buffer length bug
Date: Wed, 02 Feb 2022 14:50:24 -0800	[thread overview]
Message-ID: <20220202225024.86955-1-ramesh.thomas@intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1812 bytes --]

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.

Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 14 ++------------
 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(
 static char *accfg_get_param_str(struct accfg_ctx *ctx, int dfd, char *name)
 {
 	int fd = openat(dfd, name, O_RDONLY);
-	char buf[MAX_PARAM_LEN + 1];
+	char buf[MAX_BUF_LEN + 1];
 	int n;
 
 	if (fd == -1)
 		return NULL;
 
-	n = read(fd, buf, MAX_PARAM_LEN);
+	n = read(fd, buf, MAX_BUF_LEN);
 	close(fd);
 	if (n <= 0)
 		return NULL;
@@ -618,21 +618,13 @@ static void *add_device(void *parent, int id, const char *ctl_base,
 {
 	struct accfg_ctx *ctx = parent;
 	struct accfg_device *device;
-	char *path;
 	int dfd;
 	int rc;
 	char *p;
 
-	path = calloc(1, strlen(ctl_base) + MAX_PARAM_LEN);
-	if (!path) {
-		err(ctx, "%s: allocation of path failed\n", __func__);
-		return NULL;
-	}
-
 	dfd = open(ctl_base, O_PATH);
 	if (dfd == -1) {
 		err(ctx, "%s open failed: %s\n", __func__, strerror(errno));
-		free(path);
 		return NULL;
 	}
 
@@ -720,7 +712,6 @@ static void *add_device(void *parent, int id, const char *ctl_base,
 		goto err_dev_path;
 
 	list_add_tail(&ctx->devices, &device->list);
-	free(path);
 
 	return device;
 
@@ -730,7 +721,6 @@ err_read:
 	free(device->mdev_path);
 	free(device);
 err_device:
-	free(path);
 	return NULL;
 }
 
-- 
2.34.1

             reply	other threads:[~2022-02-02 22:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-02 22:50 Ramesh Thomas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-02-03  1:43 [Accel-config] [PATCH] accel-config: Fix a read buffer length bug Ramesh Thomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220202225024.86955-1-ramesh.thomas@intel.com \
    --to=accel-config@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.