From: Jamin Lin <jamin_lin@aspeedtech.com>
To: "clg@kaod.org" <clg@kaod.org>,
"jithu.joseph@oss.qualcomm.com" <jithu.joseph@oss.qualcomm.com>,
"open list:All patches CC here" <qemu-devel@nongnu.org>
Cc: Jamin Lin <jamin_lin@aspeedtech.com>,
Troy Lee <troy_lee@aspeedtech.com>,
Kane Chen <kane_chen@aspeedtech.com>,
"nabihestefan@google.com" <nabihestefan@google.com>,
"komlodi@google.com" <komlodi@google.com>
Subject: [PATCH v2 4/4] hw/i3c/mock-i3c-target: Simplify GETMRL byte extraction logic
Date: Tue, 3 Mar 2026 01:33:29 +0000 [thread overview]
Message-ID: <20260303013322.1297499-5-jamin_lin@aspeedtech.com> (raw)
In-Reply-To: <20260303013322.1297499-1-jamin_lin@aspeedtech.com>
The GETMRL handling logic extracted MSB/LSB bytes from
s->cfg.buf_size using a mask-and-shift expression:
(buf_size & (0xff00 >> (offset * 8))) >>
(8 - (offset * 8))
While functionally correct, the expression is difficult to read
and obscures the intent, which is simply to return a 16-bit value
in MSB-first order.
Replace the mask/shift formula with explicit MSB/LSB extraction:
offset == 0 -> buf_size >> 8
offset == 1 -> buf_size & 0xff
This makes the code clearer and easier to review without altering
behavior or data ordering.
No functional change.
Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
Reviewed-by: Jithu Joseph <jithu.joseph@oss.qualcomm.com>
---
hw/i3c/mock-i3c-target.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/hw/i3c/mock-i3c-target.c b/hw/i3c/mock-i3c-target.c
index b99709a08b..1ae2cf9e1d 100644
--- a/hw/i3c/mock-i3c-target.c
+++ b/hw/i3c/mock-i3c-target.c
@@ -146,9 +146,12 @@ static int mock_i3c_target_handle_ccc_read(I3CTarget *i3c, uint8_t *data,
if (s->ccc_byte_offset >= 2) {
break;
}
- data[s->ccc_byte_offset] = (s->cfg.buf_size &
- (0xff00 >> (s->ccc_byte_offset * 8))) >>
- (8 - (s->ccc_byte_offset * 8));
+ if (s->ccc_byte_offset == 0) {
+ data[s->ccc_byte_offset] = (uint8_t)(s->cfg.buf_size >> 8);
+ } else {
+ data[s->ccc_byte_offset] = (uint8_t)s->cfg.buf_size;
+ }
+
s->ccc_byte_offset++;
*num_read = num_to_read;
}
--
2.43.0
prev parent reply other threads:[~2026-03-03 1:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-03 1:33 [PATCH v2 0/4] hw/i3c: Trace fixes and readability improvements from review feedback Jamin Lin
2026-03-03 1:33 ` [PATCH v2 1/4] hw/i3c/dw-i3c: Use ROUND_UP() for RX buffer allocation alignment Jamin Lin
2026-03-03 1:33 ` [PATCH v2 2/4] hw/i3c/mock-i3c-target: Set num_sent in TX callback to fix trace reporting Jamin Lin
2026-03-03 1:37 ` Jithu Joseph
2026-03-03 1:33 ` [PATCH v2 3/4] hw/i3c/core: Initialize num_sent in i3c_send_byte() Jamin Lin
2026-03-03 1:33 ` Jamin Lin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260303013322.1297499-5-jamin_lin@aspeedtech.com \
--to=jamin_lin@aspeedtech.com \
--cc=clg@kaod.org \
--cc=jithu.joseph@oss.qualcomm.com \
--cc=kane_chen@aspeedtech.com \
--cc=komlodi@google.com \
--cc=nabihestefan@google.com \
--cc=qemu-devel@nongnu.org \
--cc=troy_lee@aspeedtech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.