Skip to contentSkip to conversation

Fix static analysis bugs

PATCH In review ramesh.thomas at intel.com 1 participant 8 messages Dec 4, 2020

lore
Share & tools
lore

ramesh.thomas at intel.com

#0 lore raw

cover Fix static analysis bugs

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Fixes bugs found by static code analysis

Ramesh Thomas (5):
accel-config: static analysis bug fix
accel-config: static analysis bug fix
accel-config: static analysis bug fix
accel-config: static analysis bug fix
accel-config: static analysis bug fix

 accfg/lib/libaccfg.c | 10 ++++++----
 accfg/list.c         |  3 +--
 2 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/5 accel-config: static analysis bug fix

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

group is checked for null but code continues if null. This triggers 2 issues - group and dev can be dereferenced even if null. Removing the check because the function is called only if group is not null.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/list.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
accfg/list.c +1 -2
index c22da41..2234e65 100644
@@ -56,8 +56,7 @@ static struct json_object *group_to_json(struct accfg_group *group,
 	struct json_object *jobj = NULL;
 	struct accfg_device *dev = NULL;
 
-	if (group)
-		dev = accfg_group_get_device(group);
+	dev = accfg_group_get_device(group);
 
 	if (!jgroup)
 		return NULL;
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/5 accel-config: static analysis bug fix

In reply to ramesh.thomas at intel.com

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Move dereferencing of device after the null check.

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
accfg/lib/libaccfg.c +2 -1
index cd9da42..92d3a70 100644
@@ -529,7 +529,7 @@ static void *add_wq(void *parent, int id, const char *wq_base,
 {
 	struct accfg_wq *wq;
 	struct accfg_device *device = parent;
-	struct accfg_group *group = device->group;
+	struct accfg_group *group;
 	struct accfg_ctx *ctx;
 	char *path;
 	char *wq_base_string;
@@ -540,6 +540,7 @@ static void *add_wq(void *parent, int id, const char *wq_base,
 	if (!device)
 		return NULL;
 
+	group = device->group;
 	ctx = accfg_device_get_ctx(device);
 	dfd = open(wq_base, O_PATH);
 	if (dfd < 0)
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/5 accel-config: static analysis bug fix

In reply to ramesh.thomas at intel.com

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Remove double clsing of dfd here

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 1 -
 1 file changed, 1 deletion(-)
accfg/lib/libaccfg.c +0 -1
index 92d3a70..a3f71ca 100644
@@ -616,7 +616,6 @@ err_read:
 	free(wq->wq_buf);
 	free(wq->wq_path);
 err_wq:
-	close(dfd);
 	free(wq);
 	free(path);
 	return NULL;
Signature · 1 line
2.26.2
#4 lore raw

[Accel-config] Re: [PATCH v1 3/5] accel-config: static analysis bug fix

Quoted 1 line

Remove double clsing of dfd here

Typo: closing

#5 lore raw

PATCH 4/5 accel-config: static analysis bug fix

In reply to ramesh.thomas at intel.com

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Move dereferencing of device after the null check

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
accfg/lib/libaccfg.c +2 -1
index a3f71ca..c321035 100644
@@ -715,7 +715,7 @@ static void *add_engine(void *parent, int id, const char *engine_base,
 	struct accfg_engine *engine;
 	struct accfg_device *device = parent;
 	struct accfg_ctx *ctx;
-	struct accfg_group *group = device->group;
+	struct accfg_group *group;
 	char *path;
 	char *engine_base_string;
 	int dfd;
@@ -724,6 +724,7 @@ static void *add_engine(void *parent, int id, const char *engine_base,
 	if (!device)
 		return NULL;
 
+	group = device->group;
 	ctx = accfg_device_get_ctx(device);
 	dfd = open(engine_base, O_PATH);
 	if (dfd < 0)
Signature · 1 line
2.26.2
#6 lore raw

PATCH 5/5 accel-config: static analysis bug fix

In reply to ramesh.thomas at intel.com

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Move dereferencing of dev after the null check

Signed-off-by Ramesh Thomas <ramesh.thomas(a)intel.com>
---
 accfg/lib/libaccfg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
accfg/lib/libaccfg.c +2 -1
index c321035..3b53be3 100644
@@ -1110,12 +1110,13 @@ ACCFG_EXPORT int accfg_device_get_clients(struct accfg_device *device)
 ACCFG_EXPORT int accfg_device_set_token_limit(struct accfg_device *dev, int val)
 {
 	struct accfg_ctx *ctx;
-	char *path = dev->device_buf;
+	char *path;
 	char buf[SYSFS_ATTR_SIZE];
 
 	if (!dev)
 		return -EINVAL;
 
+	path = dev->device_buf;
 	ctx = accfg_device_get_ctx(dev);
 
 	if (sprintf(path, "%s/token_limit", dev->device_path) >=
Signature · 1 line
2.26.2
Reviewed-by Dave Jiang on the v1 series
#7 lore raw
In reply to ramesh.thomas at intel.com
Quoted 10 lines

-----Original Message-----
From: ramesh.thomas(a)intel.com <ramesh.thomas(a)intel.com>
Sent: Friday, December 4, 2020 1:50 PM
To: accel-config(a)lists.01.org
Cc: Luck, Tony <tony.luck(a)intel.com>; Jiang, Dave <dave.jiang(a)intel.com>; Thomas, Ramesh <ramesh.thomas(a)intel.com>
Subject: [PATCH v1 0/5] Fix static analysis bugs

Quoted 3 lines

From: Ramesh Thomas <ramesh.thomas(a)intel.com>

Fixes bugs found by static code analysis

Reviewed-by Dave Jiang <dave.jiang(a)intel.com> for the series
Quoted 14 lines

Ramesh Thomas (5):
accel-config: static analysis bug fix
accel-config: static analysis bug fix
accel-config: static analysis bug fix
accel-config: static analysis bug fix
accel-config: static analysis bug fix

 accfg/lib/libaccfg.c | 10 ++++++----
 accfg/list.c         |  3 +--
 2 files changed, 7 insertions(+), 6 deletions(-)

--
2.26.2