Skip to contentSkip to conversation

eal/linuxapp: fix return value check of mknod()

PATCH New Zhiyong Yang 7 participants 10 messages Nov 16, 2016 – Dec 6, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal/linuxapp: fix return value check of mknod()

From: Wei Dai <[email protected]>

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes 67c536bdad93 ("pci: move uio mapping in a dedicated file")
---
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
index 1786b75..3e4ffb5 100644
@@ -133,7 +133,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 	snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num);
 	dev = makedev(major, minor);
 	ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev);
-	if (f == NULL) {
+	if (ret != 0) {
 		RTE_LOG(ERR, EAL, "%s(): mknod() failed %s\n",
 			__func__, strerror(errno));
 		return -1;
Signature · 1 line
2.5.5
#1 lore raw

PATCH v2 1/1 eal/linuxapp: fix return value check of mknod()

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes 67c536bdad93 ("pci: move uio mapping in a dedicated file")

---
fix my local git setting and send same patch again to make merging easier

 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
index 1786b75..3e4ffb5 100644
@@ -133,7 +133,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 	snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num);
 	dev = makedev(major, minor);
 	ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev);
-	if (f == NULL) {
+	if (ret != 0) {
 		RTE_LOG(ERR, EAL, "%s(): mknod() failed %s\n",
 			__func__, strerror(errno));
 		return -1;
Signature · 1 line
2.5.5
#2 lore raw

Hi Wei,

Quoted 25 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Wei Dai
Sent: Wednesday, November 16, 2016 10:41 AM
To: [email protected]; Burakov, Anatoly; [email protected]; Dai, Wei
Subject: [dpdk-dev] [PATCH v2] eal/linuxapp: fix return value check of mknod()

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen().
So the value of ret should be checked for mknod().

Fixes 67c536bdad93 ("pci: move uio mapping in a dedicated file")

---
fix my local git setting and send same patch again to make merging easier

 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +0 -0
index 1786b75..3e4ffb5 100644

lib/librte_eal/linuxapp/eal/eal_pci_uio.c pci_mknod_uio_dev(const char *sysfs_uio_path, · line 137

Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
@@ -133,7 +133,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path,
 unsigned uio_num)
 	snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num);
 	dev = makedev(major, minor);
 	ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev);
-	if (f == NULL) {
+	if (ret != 0) {

I think checkpatch will suggest to just use if (ret)

#3 lore raw

Hi Wenzhuo,

Quoted 21 lines · Wenzhuo

Hi Wei,

Quoted 19 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Wei Dai
Sent: Wednesday, November 16, 2016 10:41 AM
To: [email protected]; Burakov, Anatoly; [email protected]; Dai, Wei
Subject: [dpdk-dev] [PATCH v2] eal/linuxapp: fix return value check of mknod()

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen().
So the value of ret should be checked for mknod().

Fixes 67c536bdad93 ("pci: move uio mapping in a dedicated file")

---
fix my local git setting and send same patch again to make merging easier

 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

lib/librte_eal/linuxapp/eal/eal_pci_uio.c pci_mknod_uio_dev(const char *sysfs_uio_path, · line 137

Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
index 1786b75..3e4ffb5 100644
@@ -133,7 +133,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path,
 unsigned uio_num)
 	snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num);
 	dev = makedev(major, minor);
 	ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev);
-	if (f == NULL) {
+	if (ret != 0) {

I think checkpatch will suggest to just use if (ret)

Your are right, default checkpatch.pl complains about this usage (with --strict option), but:

- According DPDK coding style this usage is preferred (although I personally prefer kernel one..)

http://dpdk.org/doc/guides/contributing/coding_style.html#null-pointers

"
if (p == NULL) /* Good, compare pointer to NULL */

if (!p) /* Bad, using ! on pointer */
"

- This warning disabled in dpdk scripts/checkpatches.sh by "--ignore COMPARISON_TO_NULL", so it shouldn't complain.

#4 lore raw

Thanks to Yigit Ferruh and Wenzhuo for your guide.
Several months ago, I download checkpatch.pl and put it in /root/bin/.
In /root/.bash_profile in my server, there is line :export DPDK_CHECKPATCH_PATH=/root/bin/checkpatch.pl Before I send this patch, I have run checkpath.sh to check it and it show no error. ./scripts/checkpatch.sh -v v2-0001-eal-*.patch

By search ' != 0', there are many lines in many modules of DPDK. So I think ' !=0' is OK.

Quoted 68 lines

-----Original Message-----
From: Yigit, Ferruh
Sent: Wednesday, November 16, 2016 7:04 PM
To: Lu, Wenzhuo <[email protected]>; Dai, Wei <[email protected]>; [email protected]; Burakov, Anatoly <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH v2] eal/linuxapp: fix return value check of mknod()

Hi Wenzhuo,

Quoted 24 lines · Wenzhuo

Hi Wei,

Quoted 22 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Wei Dai
Sent: Wednesday, November 16, 2016 10:41 AM
To: [email protected]; Burakov, Anatoly; [email protected]; Dai, Wei
Subject: [dpdk-dev] [PATCH v2] eal/linuxapp: fix return value check of mknod()

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes 67c536bdad93 ("pci: move uio mapping in a dedicated file")

---
fix my local git setting and send same patch again to make merging easier

 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

lib/librte_eal/linuxapp/eal/eal_pci_uio.c pci_mknod_uio_dev(const char *sysfs_uio_path, · line 137

Quoted 12 lines
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
index 1786b75..3e4ffb5 100644
@@ -133,7 +133,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path,
 unsigned uio_num)
 	snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num);
 	dev = makedev(major, minor);
 	ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev);
-	if (f == NULL) {
+	if (ret != 0) {

I think checkpatch will suggest to just use if (ret)

Your are right, default checkpatch.pl complains about this usage (with --strict option), but:

- According DPDK coding style this usage is preferred (although I personally prefer kernel one..)

http://dpdk.org/doc/guides/contributing/coding_style.html#null-pointers

"
if (p == NULL) /* Good, compare pointer to NULL */

if (!p) /* Bad, using ! on pointer */
"

- This warning disabled in dpdk scripts/checkpatches.sh by "--ignore COMPARISON_TO_NULL", so it shouldn't complain.

#5 lore raw
In reply to Wei Dai

Hello Wei,

Quoted 5 lines · Wei Dai

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes 67c536bdad93 ("pci: move uio mapping in a dedicated file")

The commit you are pointing is just moving the code.
I would incriminate f7f97c16048e ("pci: add option --create-uio-dev to run without hotplug")

The rest looks good to me.

Signature · 1 line
David Marchand
#6 lore raw

Thanks to David, I will submit v3 patch to indicate correct Fixes.

Quoted 25 lines

-----Original Message-----
From: David Marchand [mailto:[email protected]]
Sent: Wednesday, November 16, 2016 7:24 PM
To: Dai, Wei <[email protected]>
Cc: [email protected]; Burakov, Anatoly <[email protected]>
Subject: Re: [PATCH v2] eal/linuxapp: fix return value check of mknod()

Hello Wei,

Quoted 5 lines · Wei Dai

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes 67c536bdad93 ("pci: move uio mapping in a dedicated file")

The commit you are pointing is just moving the code.
I would incriminate f7f97c16048e ("pci: add option --create-uio-dev to run without hotplug")

The rest looks good to me.

--
David Marchand

#7 lore raw

PATCH v3 1/1 eal/linuxapp: fix return value check of mknod()

In reply to Wei Dai

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes f7f97c16048e ("pci: add option --create-uio-dev to run without hotplug")

---
v3:
* correct Fixes: line in git commit message body

v2:
* fix my local git setting and send same patch again to remove "From: Wei Dai <[email protected]>" in git commit message body and make merging easier

 lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_pci_uio.c +1 -1
index 1786b75..3e4ffb5 100644
@@ -133,7 +133,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 	snprintf(filename, sizeof(filename), "/dev/uio%u", uio_num);
 	dev = makedev(major, minor);
 	ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev);
-	if (f == NULL) {
+	if (ret != 0) {
 		RTE_LOG(ERR, EAL, "%s(): mknod() failed %s\n",
 			__func__, strerror(errno));
 		return -1;
Signature · 1 line
2.5.5
Acked-by on v3 1/1
#8 lore raw

Hi Wei,

Quoted 8 lines · Wei Dai

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes f7f97c16048e ("pci: add option --create-uio-dev to run without

hotplug")

Thanks

#9 lore raw

2016-12-06 11:44, Olivier Matz:

Quoted 9 lines

Hi Wei,

Quoted 6 lines · Wei Dai

In function pci_mknod_uio_dev() in lib/librte_eal/eal/eal_pci_uio.c, The return value of mknod() is ret, not f got by fopen(). So the value of ret should be checked for mknod().

Fixes f7f97c16048e ("pci: add option --create-uio-dev to run without

hotplug")

Quoted 5 lines
Quoted 1 line

Thanks

Applied, thanks