[PATCH AUTOSEL 4.19 054/237] scsi: iscsi_tcp: Explicitly cast param in iscsi_sw_tcp_host_get_param

15 views
Skip to first unread message

Sasha Levin

unread,
Nov 16, 2019, 10:42:12 AM11/16/19
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Nathan Chancellor, Nick Desaulniers, Martin K . Petersen, Sasha Levin, open-...@googlegroups.com, linux...@vger.kernel.org, clang-bu...@googlegroups.com
From: Nathan Chancellor <natecha...@gmail.com>

[ Upstream commit 20054597f169090109fc3f0dfa1a48583f4178a4 ]

Clang warns when one enumerated type is implicitly converted to another.

drivers/scsi/iscsi_tcp.c:803:15: warning: implicit conversion from
enumeration type 'enum iscsi_host_param' to different enumeration type
'enum iscsi_param' [-Wenum-conversion]
&addr, param, buf);
^~~~~
1 warning generated.

iscsi_conn_get_addr_param handles ISCSI_HOST_PARAM_IPADDRESS just fine
so add an explicit cast to iscsi_param to make it clear to Clang that
this is expected behavior.

Link: https://github.com/ClangBuiltLinux/linux/issues/153
Signed-off-by: Nathan Chancellor <natecha...@gmail.com>
Reviewed-by: Nick Desaulniers <ndesau...@google.com>
Signed-off-by: Martin K. Petersen <martin....@oracle.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
drivers/scsi/iscsi_tcp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index b025a0b743417..23354f206533b 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -800,7 +800,8 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
return rc;

return iscsi_conn_get_addr_param((struct sockaddr_storage *)
- &addr, param, buf);
+ &addr,
+ (enum iscsi_param)param, buf);
default:
return iscsi_host_get_param(shost, param, buf);
}
--
2.20.1

Sasha Levin

unread,
Nov 16, 2019, 10:48:04 AM11/16/19
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Nathan Chancellor, Nick Desaulniers, Martin K . Petersen, Sasha Levin, open-...@googlegroups.com, linux...@vger.kernel.org, clang-bu...@googlegroups.com
From: Nathan Chancellor <natecha...@gmail.com>

[ Upstream commit 20054597f169090109fc3f0dfa1a48583f4178a4 ]

Clang warns when one enumerated type is implicitly converted to another.

drivers/scsi/iscsi_tcp.c:803:15: warning: implicit conversion from
enumeration type 'enum iscsi_host_param' to different enumeration type
'enum iscsi_param' [-Wenum-conversion]
&addr, param, buf);
^~~~~
1 warning generated.

iscsi_conn_get_addr_param handles ISCSI_HOST_PARAM_IPADDRESS just fine
so add an explicit cast to iscsi_param to make it clear to Clang that
this is expected behavior.

Link: https://github.com/ClangBuiltLinux/linux/issues/153
Signed-off-by: Nathan Chancellor <natecha...@gmail.com>
Reviewed-by: Nick Desaulniers <ndesau...@google.com>
Signed-off-by: Martin K. Petersen <martin....@oracle.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
drivers/scsi/iscsi_tcp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index e11eff6b0e97d..045207b5560eb 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -798,7 +798,8 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,

Sasha Levin

unread,
Nov 16, 2019, 10:51:32 AM11/16/19
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Nathan Chancellor, Nick Desaulniers, Martin K . Petersen, Sasha Levin, open-...@googlegroups.com, linux...@vger.kernel.org, clang-bu...@googlegroups.com
From: Nathan Chancellor <natecha...@gmail.com>

[ Upstream commit 20054597f169090109fc3f0dfa1a48583f4178a4 ]

Clang warns when one enumerated type is implicitly converted to another.

drivers/scsi/iscsi_tcp.c:803:15: warning: implicit conversion from
enumeration type 'enum iscsi_host_param' to different enumeration type
'enum iscsi_param' [-Wenum-conversion]
&addr, param, buf);
^~~~~
1 warning generated.

iscsi_conn_get_addr_param handles ISCSI_HOST_PARAM_IPADDRESS just fine
so add an explicit cast to iscsi_param to make it clear to Clang that
this is expected behavior.

Link: https://github.com/ClangBuiltLinux/linux/issues/153
Signed-off-by: Nathan Chancellor <natecha...@gmail.com>
Reviewed-by: Nick Desaulniers <ndesau...@google.com>
Signed-off-by: Martin K. Petersen <martin....@oracle.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
drivers/scsi/iscsi_tcp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index ace4f1f41b8e0..d60564397be54 100644

Sasha Levin

unread,
Nov 16, 2019, 10:54:02 AM11/16/19
to linux-...@vger.kernel.org, sta...@vger.kernel.org, Nathan Chancellor, Nick Desaulniers, Martin K . Petersen, Sasha Levin, open-...@googlegroups.com, linux...@vger.kernel.org, clang-bu...@googlegroups.com
From: Nathan Chancellor <natecha...@gmail.com>

[ Upstream commit 20054597f169090109fc3f0dfa1a48583f4178a4 ]

Clang warns when one enumerated type is implicitly converted to another.

drivers/scsi/iscsi_tcp.c:803:15: warning: implicit conversion from
enumeration type 'enum iscsi_host_param' to different enumeration type
'enum iscsi_param' [-Wenum-conversion]
&addr, param, buf);
^~~~~
1 warning generated.

iscsi_conn_get_addr_param handles ISCSI_HOST_PARAM_IPADDRESS just fine
so add an explicit cast to iscsi_param to make it clear to Clang that
this is expected behavior.

Link: https://github.com/ClangBuiltLinux/linux/issues/153
Signed-off-by: Nathan Chancellor <natecha...@gmail.com>
Reviewed-by: Nick Desaulniers <ndesau...@google.com>
Signed-off-by: Martin K. Petersen <martin....@oracle.com>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
drivers/scsi/iscsi_tcp.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 0b8af186e7078..fccb8991bd5b7 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -788,7 +788,8 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,

Ulrich Windl

unread,
Nov 18, 2019, 4:28:20 AM11/18/19
to open-iscsi
>>> Sasha Levin <sas...@kernel.org> schrieb am 16.11.2019 um 16:38 in Nachricht
<20191116154113...@kernel.org>:
> From: Nathan Chancellor <natecha...@gmail.com>
>
> [ Upstream commit 20054597f169090109fc3f0dfa1a48583f4178a4 ]
>
> Clang warns when one enumerated type is implicitly converted to another.

IMHO even an explicit cast doesn't make it better: Either it's the same enum, or it's a different one.
The only clean solution IMHO would be a converter function like

enum out convert_enum_in(enum in i)
{
switch (i)
{
case enum_in_1: return enum_out_1; break;
case enum_in_2: return enum_out_2; break;
...
default: bad_value(i);
}
}

Maybe a clever compiler can make this (almost) a no-op, but it should be clear that assigning different enums to each other is a bad idea.
> --
> You received this message because you are subscribed to the Google Groups
> "open-iscsi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to open-iscsi+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/open-iscsi/20191116154113.7417-54-sashal%40
> kernel.org.




Reply all
Reply to author
Forward
0 new messages