[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 08/76] sd: convert sd_normal_command() ffs(3) call to
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 08/76] sd: convert sd_normal_command() ffs(3) call to ctz32() |
Date: |
Tue, 28 Apr 2015 16:59:50 +0200 |
From: Stefan Hajnoczi <address@hidden>
ffs() cannot be replaced with ctz32() when the argument might be zero,
because ffs(0) returns 0 while ctz32(0) returns 32.
The ffs(3) call in sd_normal_command() is a special case though. It can
be converted to ctz32() + 1 because the argument is never zero:
if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) {
~~~~~~~~~~~~~~~
^--------------- req.arg cannot be zero
Cc: Markus Armbruster <address@hidden>
Cc: Peter Crosthwaite <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Message-id: address@hidden
Signed-off-by: Kevin Wolf <address@hidden>
---
hw/sd/sd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index f955265..8abf0c9 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -796,8 +796,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
sd->vhs = 0;
/* No response if not exactly one VHS bit is set. */
- if (!(req.arg >> 8) || (req.arg >> ffs(req.arg & ~0xff)))
+ if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) {
return sd->spi ? sd_r7 : sd_r0;
+ }
/* Accept. */
sd->vhs = req.arg;
--
1.8.3.1
- [Qemu-block] [PULL 00/76] Block patches, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 02/76] MAINTAINERS: Add myself as the maintainer of the Quorum driver, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 01/76] savevm: create snapshot failed when id_str already exists, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 03/76] bt-sdp: fix broken uuids power-of-2 calculation, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 04/76] hw/arm/nseries: convert ffs(3) to ctz32(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 05/76] uninorth: convert ffs(3) to ctz32(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 07/76] Convert ffs() != 0 callers to ctz32(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 08/76] sd: convert sd_normal_command() ffs(3) call to ctz32(),
Kevin Wolf <=
- [Qemu-block] [PULL 09/76] omap_intc: convert ffs(3) to ctz32() in omap_inth_sir_update(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 06/76] Convert (ffs(val) - 1) to ctz32(val), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 10/76] os-win32: drop ffs(3) prototype, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 11/76] checkpatch: complain about ffs(3) calls, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 12/76] block: Switch to host monotonic clock for IO throttling, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 13/76] aio-posix: move pollfds to thread-local storage, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 15/76] iothread: release iothread around aio_poll, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 14/76] AioContext: acquire/release AioContext during aio_poll, Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 16/76] block-backend: Expose bdrv_write_zeroes(), Kevin Wolf, 2015/04/28
- [Qemu-block] [PULL 18/76] qemu-iotests: Some qemu-img convert tests, Kevin Wolf, 2015/04/28