linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ v1] shared/vcp: Fix comparison of values in different endianess
@ 2023-12-04 22:07 Luiz Augusto von Dentz
  2023-12-04 23:23 ` [BlueZ,v1] " bluez.test.bot
  2023-12-05  3:40 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2023-12-04 22:07 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Values received over the air are in Little Endian format so they first
need to be converted to host endianess before comparing with other
values.
---
 src/shared/vcp.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/shared/vcp.c b/src/shared/vcp.c
index 06a22997a95c..5d163266b480 100644
--- a/src/shared/vcp.c
+++ b/src/shared/vcp.c
@@ -709,13 +709,16 @@ static uint8_t vocs_set_vol_offset(struct bt_vocs *vocs, struct bt_vcp *vcp,
 		return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
 	}
 
-	if (req->set_vol_offset > VOCS_VOL_OFFSET_UPPER_LIMIT ||
-		req->set_vol_offset < VOCS_VOL_OFFSET_LOWER_LIMIT) {
+	vstate->vol_offset = le16_to_cpu(req->set_vol_offset);
+
+	if (vstate->vol_offset > VOCS_VOL_OFFSET_UPPER_LIMIT ||
+		vstate->vol_offset < VOCS_VOL_OFFSET_LOWER_LIMIT) {
 		DBG(vcp, "error: Value Out of Range");
 		return BT_ATT_ERROR_VALUE_OUT_OF_RANGE;
 	}
-	vstate->vol_offset = le16_to_cpu(req->set_vol_offset);
-	vstate->counter = -~vstate->counter; /*Increment Change Counter*/
+
+	/* Increment Change Counter */
+	vstate->counter = -~vstate->counter;
 
 	gatt_db_attribute_notify(vdb->vocs->vos, (void *)vstate,
 				 sizeof(struct vol_offset_state),
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-05  3:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04 22:07 [PATCH BlueZ v1] shared/vcp: Fix comparison of values in different endianess Luiz Augusto von Dentz
2023-12-04 23:23 ` [BlueZ,v1] " bluez.test.bot
2023-12-05  3:40 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).