Skip to contentSkip to conversation

target: iscsi: fix clang -Wformat warning

PATCH Superseded Justin Stitt 4 participants 7 messages Jul 8, 2022 – Jul 27, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: iscsi: fix clang -Wformat warning

When building with Clang we encounter these warnings:

| drivers/target/iscsi/iscsi_target_login.c:719:24: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " from node: %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target_login.c:767:12: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " %s\n", atomic_read(&sess->nconn),

For both warnings, the format specifier is %hu which describes an unsigned short. The resulting type of atomic_read is an int. The proposed fix is to listen to Clang and swap the format specifier.

---
 drivers/target/iscsi/iscsi_target_login.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target_login.c +2 -2
index 6b94eecc4790..0778591abae7 100644
@@ -715,7 +715,7 @@ void iscsi_post_login_handler(
 
 		list_add_tail(&conn->conn_list, &sess->sess_conn_list);
 		atomic_inc(&sess->nconn);
-		pr_debug("Incremented iSCSI Connection count to %hu"
+		pr_debug("Incremented iSCSI Connection count to %d"
 			" from node: %s\n", atomic_read(&sess->nconn),
 			sess->sess_ops->InitiatorName);
 		spin_unlock_bh(&sess->conn_lock);
@@ -763,7 +763,7 @@ void iscsi_post_login_handler(
 	spin_lock_bh(&sess->conn_lock);
 	list_add_tail(&conn->conn_list, &sess->sess_conn_list);
 	atomic_inc(&sess->nconn);
-	pr_debug("Incremented iSCSI Connection count to %hu from node:"
+	pr_debug("Incremented iSCSI Connection count to %d from node:"
 		" %s\n", atomic_read(&sess->nconn),
 		sess->sess_ops->InitiatorName);
 	spin_unlock_bh(&sess->conn_lock);
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
#1 lore raw
Quoted 10 lines · Justin Stitt

When building with Clang we encounter these warnings:

| drivers/target/iscsi/iscsi_target_login.c:719:24: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " from node: %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target_login.c:767:12: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " %s\n", atomic_read(&sess->nconn),
Quoted 6 lines

For both warnings, the format specifier is %hu which describes an unsigned short. The resulting type of atomic_read is an int. The proposed fix is to listen to Clang and swap the format specifier.

See also:
https://lore.kernel.org/lkml/CAKwvOd=uOrDe5DWnXn7fx8+kTCF6gQVYhgqpnDFbaKunfBBVVg@mail.gmail.com/

Quoted 29 lines
---
 drivers/target/iscsi/iscsi_target_login.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/target/iscsi/iscsi_target_login.c +2 -3
index 6b94eecc4790..0778591abae7 100644
@@ -715,7 +715,7 @@ void iscsi_post_login_handler(
 
                list_add_tail(&conn->conn_list, &sess->sess_conn_list);
                atomic_inc(&sess->nconn);
-               pr_debug("Incremented iSCSI Connection count to %hu"
+               pr_debug("Incremented iSCSI Connection count to %d"
                        " from node: %s\n", atomic_read(&sess->nconn),
                        sess->sess_ops->InitiatorName);
                spin_unlock_bh(&sess->conn_lock);
@@ -763,7 +763,7 @@ void iscsi_post_login_handler(
        spin_lock_bh(&sess->conn_lock);
        list_add_tail(&conn->conn_list, &sess->sess_conn_list);
        atomic_inc(&sess->nconn);
-       pr_debug("Incremented iSCSI Connection count to %hu from node:"
+       pr_debug("Incremented iSCSI Connection count to %d from node:"
                " %s\n", atomic_read(&sess->nconn),
                sess->sess_ops->InitiatorName);
        spin_unlock_bh(&sess->conn_lock);
--

2.37.0.rc0.161.g10f37bed90-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw

PATCH v2 1/1 target: iscsi: fix clang -Wformat warnings

In reply to Justin Stitt

When building with Clang we encounter these warnings:

| drivers/target/iscsi/iscsi_target_login.c:719:24: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " from node: %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target_login.c:767:12: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target.c:4365:12: error: format specifies
| type 'unsigned short' but the argument has type 'int' [-Werror,-Wformat]
| " %s\n", atomic_read(&sess->nconn)

For all warnings, the format specifier is %hu which describes an unsigned short. The resulting type of atomic_read is an int. The proposed fix is to listen to Clang and swap the format specifier.

---
diff from v1->v2:
Combined two similar patches into one:
* https://lore.kernel.org/all/[email protected]/
* https://lore.kernel.org/llvm/[email protected]/

 drivers/target/iscsi/iscsi_target.c       | 2 +-
 drivers/target/iscsi/iscsi_target_login.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/target/iscsi/iscsi_target.c +1 -1
index e368f038ff5c..bfb717065344 100644
@@ -4361,7 +4361,7 @@ int iscsit_close_connection(
 
 	spin_lock_bh(&sess->conn_lock);
 	atomic_dec(&sess->nconn);
-	pr_debug("Decremented iSCSI connection count to %hu from node:"
+	pr_debug("Decremented iSCSI connection count to %d from node:"
 		" %s\n", atomic_read(&sess->nconn),
 		sess->sess_ops->InitiatorName);
 	/*
drivers/target/iscsi/iscsi_target_login.c +2 -2
index 6b94eecc4790..0778591abae7 100644
@@ -715,7 +715,7 @@ void iscsi_post_login_handler(
 
 		list_add_tail(&conn->conn_list, &sess->sess_conn_list);
 		atomic_inc(&sess->nconn);
-		pr_debug("Incremented iSCSI Connection count to %hu"
+		pr_debug("Incremented iSCSI Connection count to %d"
 			" from node: %s\n", atomic_read(&sess->nconn),
 			sess->sess_ops->InitiatorName);
 		spin_unlock_bh(&sess->conn_lock);
@@ -763,7 +763,7 @@ void iscsi_post_login_handler(
 	spin_lock_bh(&sess->conn_lock);
 	list_add_tail(&conn->conn_list, &sess->sess_conn_list);
 	atomic_inc(&sess->nconn);
-	pr_debug("Incremented iSCSI Connection count to %hu from node:"
+	pr_debug("Incremented iSCSI Connection count to %d from node:"
 		" %s\n", atomic_read(&sess->nconn),
 		sess->sess_ops->InitiatorName);
 	spin_unlock_bh(&sess->conn_lock);
Signature · 1 line
2.37.0.170.g444d1eabd0-goog
Reviewed-by on v2 1/1
#3 lore raw

Re: [PATCH v2] target: iscsi: fix clang -Wformat warnings

Quoted 14 lines · Justin Stitt

When building with Clang we encounter these warnings:

| drivers/target/iscsi/iscsi_target_login.c:719:24: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " from node: %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target_login.c:767:12: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target.c:4365:12: error: format specifies
| type 'unsigned short' but the argument has type 'int' [-Werror,-Wformat]
| " %s\n", atomic_read(&sess->nconn)
Quoted 6 lines

For all warnings, the format specifier is %hu which describes an unsigned short. The resulting type of atomic_read is an int. The proposed fix is to listen to Clang and swap the format specifier.

Thanks for the patch!

Quoted 48 lines

---
diff from v1->v2:
Combined two similar patches into one:
* https://lore.kernel.org/all/[email protected]/
* https://lore.kernel.org/llvm/[email protected]/

 drivers/target/iscsi/iscsi_target.c       | 2 +-
 drivers/target/iscsi/iscsi_target_login.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/target/iscsi/iscsi_target.c +1 -1
index e368f038ff5c..bfb717065344 100644
@@ -4361,7 +4361,7 @@ int iscsit_close_connection(
 
        spin_lock_bh(&sess->conn_lock);
        atomic_dec(&sess->nconn);
-       pr_debug("Decremented iSCSI connection count to %hu from node:"
+       pr_debug("Decremented iSCSI connection count to %d from node:"
                " %s\n", atomic_read(&sess->nconn),
                sess->sess_ops->InitiatorName);
        /*
drivers/target/iscsi/iscsi_target_login.c +2 -3
index 6b94eecc4790..0778591abae7 100644
@@ -715,7 +715,7 @@ void iscsi_post_login_handler(
 
                list_add_tail(&conn->conn_list, &sess->sess_conn_list);
                atomic_inc(&sess->nconn);
-               pr_debug("Incremented iSCSI Connection count to %hu"
+               pr_debug("Incremented iSCSI Connection count to %d"
                        " from node: %s\n", atomic_read(&sess->nconn),
                        sess->sess_ops->InitiatorName);
                spin_unlock_bh(&sess->conn_lock);
@@ -763,7 +763,7 @@ void iscsi_post_login_handler(
        spin_lock_bh(&sess->conn_lock);
        list_add_tail(&conn->conn_list, &sess->sess_conn_list);
        atomic_inc(&sess->nconn);
-       pr_debug("Incremented iSCSI Connection count to %hu from node:"
+       pr_debug("Incremented iSCSI Connection count to %d from node:"
                " %s\n", atomic_read(&sess->nconn),
                sess->sess_ops->InitiatorName);
        spin_unlock_bh(&sess->conn_lock);
--

2.37.0.170.g444d1eabd0-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH v2] target: iscsi: fix clang -Wformat warnings

In reply to Justin Stitt
Quoted 13 lines · Justin Stitt

When building with Clang we encounter these warnings:

| drivers/target/iscsi/iscsi_target_login.c:719:24: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " from node: %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target_login.c:767:12: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target.c:4365:12: error: format specifies
| type 'unsigned short' but the argument has type 'int' [-Werror,-Wformat]
| " %s\n", atomic_read(&sess->nconn)
Quoted 6 lines

For all warnings, the format specifier is %hu which describes an unsigned short. The resulting type of atomic_read is an int. The proposed fix is to listen to Clang and swap the format specifier.

Looks good.

-ck

#5 lore raw

Re: [PATCH v2] target: iscsi: fix clang -Wformat warnings

In reply to Justin Stitt

Justin,

Quoted 3 lines

For all warnings, the format specifier is %hu which describes an unsigned short. The resulting type of atomic_read is an int. The proposed fix is to listen to Clang and swap the format specifier.

Applied to 5.20/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#6 lore raw

Re: [PATCH v2] target: iscsi: fix clang -Wformat warnings

In reply to Justin Stitt
Quoted 13 lines · Justin Stitt

When building with Clang we encounter these warnings:

| drivers/target/iscsi/iscsi_target_login.c:719:24: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " from node: %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target_login.c:767:12: error: format
| specifies type 'unsigned short' but the argument has type 'int'
| [-Werror,-Wformat] " %s\n", atomic_read(&sess->nconn),
-
| drivers/target/iscsi/iscsi_target.c:4365:12: error: format specifies
| type 'unsigned short' but the argument has type 'int' [-Werror,-Wformat]
| " %s\n", atomic_read(&sess->nconn)
Quoted 1 line

[...]

Applied to 5.20/scsi-queue, thanks!

[1/1] target: iscsi: fix clang -Wformat warnings

      https://git.kernel.org/mkp/scsi/c/71b25693b22e
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering