Message ID | 20210413170714.2119-10-bvanassche@acm.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | SCSI patches for kernel v5.13 | expand |
On Tue, 2021-04-13 at 10:07 -0700, Bart Van Assche wrote: > Suppress two instances of the following clang compiler warning: > > warning: format specifies type 'unsigned short' > but the argument has type 'int' [-Wformat] > > Cc: Lee Duncan <lduncan@suse.com> > Cc: Chris Leech <cleech@redhat.com> > Signed-off-by: Bart Van Assche <bvanassche@acm.org> > --- > drivers/scsi/libiscsi.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c > index 7ad11e42306d..0c3082d09712 100644 > --- a/drivers/scsi/libiscsi.c > +++ b/drivers/scsi/libiscsi.c > @@ -3587,10 +3587,11 @@ int iscsi_conn_get_addr_param(struct > sockaddr_storage *addr, > case ISCSI_PARAM_CONN_PORT: > case ISCSI_PARAM_LOCAL_PORT: > if (sin) > - len = sprintf(buf, "%hu\n", be16_to_cpu(sin- > >sin_port)); > + len = sprintf(buf, "%hu\n", > + (u16)be16_to_cpu(sin->sin_port)); > else > len = sprintf(buf, "%hu\n", > - be16_to_cpu(sin6->sin6_port)); > + (u16)be16_to_cpu(sin6- > This looks odd: the generic definition of be16_to_cpu on le is #define __be16_to_cpu(x) __swab16((__force __u16)(__be16)(x)) and __swab16 is #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) So why doesn't clang see the existing __u16 as short? This smells like a problem in the compiler file. James
On 4/13/21 10:59 AM, James Bottomley wrote: > On Tue, 2021-04-13 at 10:07 -0700, Bart Van Assche wrote: >> Suppress two instances of the following clang compiler warning: >> >> warning: format specifies type 'unsigned short' >> but the argument has type 'int' [-Wformat] >> >> Cc: Lee Duncan <lduncan@suse.com> >> Cc: Chris Leech <cleech@redhat.com> >> Signed-off-by: Bart Van Assche <bvanassche@acm.org> >> --- >> drivers/scsi/libiscsi.c | 5 +++-- >> 1 file changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c >> index 7ad11e42306d..0c3082d09712 100644 >> --- a/drivers/scsi/libiscsi.c >> +++ b/drivers/scsi/libiscsi.c >> @@ -3587,10 +3587,11 @@ int iscsi_conn_get_addr_param(struct >> sockaddr_storage *addr, >> case ISCSI_PARAM_CONN_PORT: >> case ISCSI_PARAM_LOCAL_PORT: >> if (sin) >> - len = sprintf(buf, "%hu\n", be16_to_cpu(sin- >>> sin_port)); >> + len = sprintf(buf, "%hu\n", >> + (u16)be16_to_cpu(sin->sin_port)); >> else >> len = sprintf(buf, "%hu\n", >> - be16_to_cpu(sin6->sin6_port)); >> + (u16)be16_to_cpu(sin6- >> > > This looks odd: the generic definition of be16_to_cpu on le is > > #define __be16_to_cpu(x) __swab16((__force __u16)(__be16)(x)) > > and __swab16 is > > #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) > > So why doesn't clang see the existing __u16 as short? This smells like > a problem in the compiler file. Hi James, To me this also seems to be a compiler issue. I will drop this patch since I prefer not to insert casts if an expression already has the proper type. Thanks, Bart.
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 7ad11e42306d..0c3082d09712 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -3587,10 +3587,11 @@ int iscsi_conn_get_addr_param(struct sockaddr_storage *addr, case ISCSI_PARAM_CONN_PORT: case ISCSI_PARAM_LOCAL_PORT: if (sin) - len = sprintf(buf, "%hu\n", be16_to_cpu(sin->sin_port)); + len = sprintf(buf, "%hu\n", + (u16)be16_to_cpu(sin->sin_port)); else len = sprintf(buf, "%hu\n", - be16_to_cpu(sin6->sin6_port)); + (u16)be16_to_cpu(sin6->sin6_port)); break; default: return -EINVAL;
Suppress two instances of the following clang compiler warning: warning: format specifies type 'unsigned short' but the argument has type 'int' [-Wformat] Cc: Lee Duncan <lduncan@suse.com> Cc: Chris Leech <cleech@redhat.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- drivers/scsi/libiscsi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)