* [PATCH] nvme: use upper_32_bits() instead of bit shift
@ 2018-03-28 13:57 ` Arnd Bergmann
0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2018-03-28 13:57 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
Cc: Matias Bjørling, Arnd Bergmann, Johannes Thumshirn,
Hannes Reinecke, linux-nvme, linux-kernel
On 32-bit architectures, we cannot shift a size_t by 32 bits to the right
without a compiler warning:
drivers/nvme/host/core.c: In function 'nvme_get_log_ext':
drivers/nvme/host/core.c:2237:43: error: right shift count >= width of type [-Werror=shift-count-overflow]
c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
^~
include/uapi/linux/byteorder/little_endian.h:33:51: note: in definition of macro '__cpu_to_le32'
#define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
^
drivers/nvme/host/core.c:2237:24: note: in expansion of macro 'cpu_to_le32'
c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
The code is correct, but using the upper_32_bits() and lower_32_bits()
macros that were introduced for this operation makes it easier to read
and avoids the warning.
Fixes: 70da6094a646 ("nvme: implement log page low/high offset and dwords")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/nvme/host/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4e4136bfc37f..0a81704b763f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2233,8 +2233,8 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.get_log_page.lid = log_page;
c.get_log_page.numdl = cpu_to_le16(dwlen & ((1 << 16) - 1));
c.get_log_page.numdu = cpu_to_le16(dwlen >> 16);
- c.get_log_page.lpol = cpu_to_le32(offset & ((1ULL << 32) - 1));
- c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
+ c.get_log_page.lpol = cpu_to_le32(lower_32_bits(offset));
+ c.get_log_page.lpou = cpu_to_le32(upper_32_bits(offset));
return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size);
}
--
2.9.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] nvme: use upper_32_bits() instead of bit shift
@ 2018-03-28 13:57 ` Arnd Bergmann
0 siblings, 0 replies; 6+ messages in thread
From: Arnd Bergmann @ 2018-03-28 13:57 UTC (permalink / raw)
On 32-bit architectures, we cannot shift a size_t by 32 bits to the right
without a compiler warning:
drivers/nvme/host/core.c: In function 'nvme_get_log_ext':
drivers/nvme/host/core.c:2237:43: error: right shift count >= width of type [-Werror=shift-count-overflow]
c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
^~
include/uapi/linux/byteorder/little_endian.h:33:51: note: in definition of macro '__cpu_to_le32'
#define __cpu_to_le32(x) ((__force __le32)(__u32)(x))
^
drivers/nvme/host/core.c:2237:24: note: in expansion of macro 'cpu_to_le32'
c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
The code is correct, but using the upper_32_bits() and lower_32_bits()
macros that were introduced for this operation makes it easier to read
and avoids the warning.
Fixes: 70da6094a646 ("nvme: implement log page low/high offset and dwords")
Signed-off-by: Arnd Bergmann <arnd at arndb.de>
---
drivers/nvme/host/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 4e4136bfc37f..0a81704b763f 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2233,8 +2233,8 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
c.get_log_page.lid = log_page;
c.get_log_page.numdl = cpu_to_le16(dwlen & ((1 << 16) - 1));
c.get_log_page.numdu = cpu_to_le16(dwlen >> 16);
- c.get_log_page.lpol = cpu_to_le32(offset & ((1ULL << 32) - 1));
- c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
+ c.get_log_page.lpol = cpu_to_le32(lower_32_bits(offset));
+ c.get_log_page.lpou = cpu_to_le32(upper_32_bits(offset));
return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size);
}
--
2.9.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] nvme: use upper_32_bits() instead of bit shift
2018-03-28 13:57 ` Arnd Bergmann
@ 2018-03-28 14:05 ` Johannes Thumshirn
-1 siblings, 0 replies; 6+ messages in thread
From: Johannes Thumshirn @ 2018-03-28 14:05 UTC (permalink / raw)
To: Arnd Bergmann, Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
Cc: Matias Bjørling, Hannes Reinecke, linux-nvme, linux-kernel
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
--
Johannes Thumshirn Storage
jthumshirn@suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] nvme: use upper_32_bits() instead of bit shift
@ 2018-03-28 14:05 ` Johannes Thumshirn
0 siblings, 0 replies; 6+ messages in thread
From: Johannes Thumshirn @ 2018-03-28 14:05 UTC (permalink / raw)
Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de>
--
Johannes Thumshirn Storage
jthumshirn at suse.de +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] nvme: use upper_32_bits() instead of bit shift
2018-03-28 13:57 ` Arnd Bergmann
@ 2018-03-28 14:20 ` Keith Busch
-1 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2018-03-28 14:20 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Matias Bjørling, Johannes Thumshirn, Hannes Reinecke,
linux-nvme, linux-kernel
On Wed, Mar 28, 2018 at 03:57:47PM +0200, Arnd Bergmann wrote:
> @@ -2233,8 +2233,8 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> c.get_log_page.lid = log_page;
> c.get_log_page.numdl = cpu_to_le16(dwlen & ((1 << 16) - 1));
> c.get_log_page.numdu = cpu_to_le16(dwlen >> 16);
> - c.get_log_page.lpol = cpu_to_le32(offset & ((1ULL << 32) - 1));
> - c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
> + c.get_log_page.lpol = cpu_to_le32(lower_32_bits(offset));
> + c.get_log_page.lpou = cpu_to_le32(upper_32_bits(offset));
>
> return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size);
> }
Right, Matias posted the same fix here:
http://lists.infradead.org/pipermail/linux-nvme/2018-March/016474.html
In addition to the type safe shifting, a 64-bit type was used to match
the spec.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] nvme: use upper_32_bits() instead of bit shift
@ 2018-03-28 14:20 ` Keith Busch
0 siblings, 0 replies; 6+ messages in thread
From: Keith Busch @ 2018-03-28 14:20 UTC (permalink / raw)
On Wed, Mar 28, 2018@03:57:47PM +0200, Arnd Bergmann wrote:
> @@ -2233,8 +2233,8 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
> c.get_log_page.lid = log_page;
> c.get_log_page.numdl = cpu_to_le16(dwlen & ((1 << 16) - 1));
> c.get_log_page.numdu = cpu_to_le16(dwlen >> 16);
> - c.get_log_page.lpol = cpu_to_le32(offset & ((1ULL << 32) - 1));
> - c.get_log_page.lpou = cpu_to_le32(offset >> 32ULL);
> + c.get_log_page.lpol = cpu_to_le32(lower_32_bits(offset));
> + c.get_log_page.lpou = cpu_to_le32(upper_32_bits(offset));
>
> return nvme_submit_sync_cmd(ctrl->admin_q, &c, log, size);
> }
Right, Matias posted the same fix here:
http://lists.infradead.org/pipermail/linux-nvme/2018-March/016474.html
In addition to the type safe shifting, a 64-bit type was used to match
the spec.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-03-28 14:20 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28 13:57 [PATCH] nvme: use upper_32_bits() instead of bit shift Arnd Bergmann
2018-03-28 13:57 ` Arnd Bergmann
2018-03-28 14:05 ` Johannes Thumshirn
2018-03-28 14:05 ` Johannes Thumshirn
2018-03-28 14:20 ` Keith Busch
2018-03-28 14:20 ` Keith Busch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.