Skip to contentSkip to conversation

crypto: qat - fix excluded_middle.cocci warnings

PATCH In review Julia Lawall 3 participants 4 messages Nov 13, 2020 – Nov 27, 2020 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: qat - fix excluded_middle.cocci warnings

From: kernel test robot <[email protected]>

Condition !A || A && B is equivalent to !A || B.

Generated by: scripts/coccinelle/misc/excluded_middle.cocci

Fixes b76f0ea01312 ("coccinelle: misc: add excluded_middle.cocci script")
CC Denis Efremov <[email protected]>

---

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   585e5b17b92dead8a3aca4e3c9876fbca5f7e0ba
commit: b76f0ea013125358d1b4ca147a6f9b6883dd2493 coccinelle: misc: add excluded_middle.cocci script

:::::: branch date: 14 hours ago
:::::: commit date: 8 weeks ago

Please take the patch only if it's a positive warning. Thanks!

 adf_dev_mgr.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/crypto/qat/qat_common/adf_dev_mgr.c +2 -2
@@ -152,7 +152,7 @@ int adf_devmgr_add_dev(struct adf_accel_
 	atomic_set(&accel_dev->ref_count, 0);
 
 	/* PF on host or VF on guest */
-	if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) {
+	if (!accel_dev->is_vf || !pf) {
 		struct vf_id_map *map;
 
 		list_for_each(itr, &accel_table) {
@@ -248,7 +248,7 @@ void adf_devmgr_rm_dev(struct adf_accel_
 		       struct adf_accel_dev *pf)
 {
 	mutex_lock(&table_lock);
-	if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) {
+	if (!accel_dev->is_vf || !pf) {
 		id_map[accel_dev->accel_id] = 0;
 		num_devices--;
 	} else if (accel_dev->is_vf && pf) {
#1 lore raw
Quoted 3 lines · Julia Lawall

From: kernel test robot <[email protected]>

Condition !A || A && B is equivalent to !A || B.

A similar change was submitted and discussed some time ago:
https://patchwork.kernel.org/project/linux-crypto/patch/78b1532c-f8bf-48e4-d0a7-30ea0137d408(a)huawei.com/

The change simplifies the logic but makes the code less readable. I added a comment to clarify it.

Regards,

Signature · 20 lines
Giovanni

----8<----
From: kernel test robot <[email protected]>
Date: Fri, 13 Nov 2020 18:14:00 +0100
Subject: [PATCH] crypto: qat - fix excluded_middle.cocci warnings

 Condition !A || A && B is equivalent to !A || B.

Generated by: scripts/coccinelle/misc/excluded_middle.cocci

Fixes: b76f0ea01312 ("coccinelle: misc: add excluded_middle.cocci script")
CC: Denis Efremov <[email protected]>
Reported-by: kernel test robot <[email protected]>
Signed-off-by: kernel test robot <[email protected]>
Signed-off-by: Julia Lawall <[email protected]>
Signed-off-by: Giovanni Cabiddu <[email protected]>
---
 drivers/crypto/qat/qat_common/adf_dev_mgr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/qat/qat_common/adf_dev_mgr.c +4 -3
index 29dc2e3d38ff..4c752eed10fe 100644
@@ -151,8 +151,8 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,
 	mutex_lock(&table_lock);
 	atomic_set(&accel_dev->ref_count, 0);
 
-	/* PF on host or VF on guest */
-	if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) {
+	/* PF on host or VF on guest - optimized to remove redundant is_vf */
+	if (!accel_dev->is_vf || !pf) {
 		struct vf_id_map *map;
 
 		list_for_each(itr, &accel_table) {
@@ -248,7 +248,8 @@ void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev,
 		       struct adf_accel_dev *pf)
 {
 	mutex_lock(&table_lock);
-	if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) {
+	/* PF on host or VF on guest - optimized to remove redundant is_vf */
+	if (!accel_dev->is_vf || !pf) {
 		id_map[accel_dev->accel_id] = 0;
 		num_devices--;
 	} else if (accel_dev->is_vf && pf) {
Signature · 1 line
2.28.0
#2 lore raw

PATCH RESEND 1/1 crypto: qat - fix excluded_middle.cocci warnings

Quoted 9 lines · Giovanni Cabiddu
Quoted 3 lines · Julia Lawall

From: kernel test robot <[email protected]>

Condition !A || A && B is equivalent to !A || B.

A similar change was submitted and discussed some time ago:
https://patchwork.kernel.org/project/linux-crypto/patch/78b1532c-f8bf-48e4-d0a7-30ea0137d408(a)huawei.com/

The change simplifies the logic but makes the code less readable. I added a comment to clarify it.

Resending as it skipped linux-crypto patchwork.

----8<----

From: kernel test robot <[email protected]>
Date: Fri, 13 Nov 2020 18:14:00 +0100
Subject: [PATCH] crypto: qat - fix excluded_middle.cocci warnings

Condition !A || A && B is equivalent to !A || B.

Generated by: scripts/coccinelle/misc/excluded_middle.cocci

Fixes b76f0ea01312 ("coccinelle: misc: add excluded_middle.cocci script")
CC Denis Efremov <[email protected]>
---
 drivers/crypto/qat/qat_common/adf_dev_mgr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/crypto/qat/qat_common/adf_dev_mgr.c +4 -3
index 29dc2e3d38ff..4c752eed10fe 100644
@@ -151,8 +151,8 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,
 	mutex_lock(&table_lock);
 	atomic_set(&accel_dev->ref_count, 0);
 
-	/* PF on host or VF on guest */
-	if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) {
+	/* PF on host or VF on guest - optimized to remove redundant is_vf */
+	if (!accel_dev->is_vf || !pf) {
 		struct vf_id_map *map;
 
 		list_for_each(itr, &accel_table) {
@@ -248,7 +248,8 @@ void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev,
 		       struct adf_accel_dev *pf)
 {
 	mutex_lock(&table_lock);
-	if (!accel_dev->is_vf || (accel_dev->is_vf && !pf)) {
+	/* PF on host or VF on guest - optimized to remove redundant is_vf */
+	if (!accel_dev->is_vf || !pf) {
 		id_map[accel_dev->accel_id] = 0;
 		num_devices--;
 	} else if (accel_dev->is_vf && pf) {
Signature · 1 line
2.28.0
maintainer
#3 lore raw
Quoted 11 lines · Giovanni Cabiddu

Condition !A || A && B is equivalent to !A || B.

Generated by: scripts/coccinelle/misc/excluded_middle.cocci

Fixes b76f0ea01312 ("coccinelle: misc: add excluded_middle.cocci script")
CC Denis Efremov <[email protected]>
Quoted 3 lines
---
 drivers/crypto/qat/qat_common/adf_dev_mgr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt