Skip to contentSkip to conversation

bap: Allocate memory for broadcast code

PATCH Applied Vlad Pruteanu 3 participants 5 messages Jun 19, 2024 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

v2 cover bap: Allocate memory for broadcast code

Currently the broadcast code is set without memory being allocated for it resulting in segmentation fault. This implements an util_iov_new function that allocates the memory before setting the user_data. The issue is fixed by using this function instead of util_iov_append.

Vlad Pruteanu (2):
shared/util: Add util_iov_new function
bap: Use util_iov_new when setting bcode

 profiles/audio/bap.c |  5 ++---
 src/shared/util.c    | 10 ++++++++++
 src/shared/util.h    |  1 +
 3 files changed, 13 insertions(+), 3 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 1/2 shared/util: Add util_iov_new function

This adds the util_iov_new function that allows the user both allocated and set an iovec to the desired value, using only one function call.

---
 src/shared/util.c | 10 ++++++++++
 src/shared/util.h |  1 +
 2 files changed, 11 insertions(+)
src/shared/util.c +10 -0
index 6a29b5068..30f054a5e 100644
@@ -542,6 +542,16 @@ void *util_iov_append(struct iovec *iov, const void *data, size_t len)
 	return util_iov_push_mem(iov, len, data);
 }
 
+struct iovec *util_iov_new(void *data, size_t len)
+{
+	struct iovec *iov;
+
+	iov = new0(struct iovec, 1);
+	util_iov_append(iov, data, len);
+
+	return iov;
+}
+
 void *util_iov_pull(struct iovec *iov, size_t len)
 {
 	if (!iov)
src/shared/util.h +1 -0
index bd71577d6..f2ca4f29f 100644
@@ -176,6 +176,7 @@ void *util_iov_push_le16(struct iovec *iov, uint16_t val);
 void *util_iov_push_be16(struct iovec *iov, uint16_t val);
 void *util_iov_push_u8(struct iovec *iov, uint8_t val);
 void *util_iov_append(struct iovec *iov, const void *data, size_t len);
+struct iovec *util_iov_new(void *data, size_t len);
 void *util_iov_pull(struct iovec *iov, size_t len);
 void *util_iov_pull_mem(struct iovec *iov, size_t len);
 void *util_iov_pull_le64(struct iovec *iov, uint64_t *val);
Signature · 1 line
2.40.1
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=863362

---Test result---

Test Summary:

CheckPatch                    PASS      0.95 seconds
GitLint                       PASS      0.67 seconds
BuildEll                      PASS      24.51 seconds
BluezMake                     PASS      1675.31 seconds
MakeCheck                     PASS      13.64 seconds
MakeDistcheck                 PASS      176.61 seconds
CheckValgrind                 PASS      250.75 seconds
CheckSmatch                   PASS      352.42 seconds
bluezmakeextell               PASS      119.14 seconds
IncrementalBuild              PASS      2986.68 seconds
ScanBuild                     WARNING   1020.79 seconds

Details
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
In file included from tools/mesh-gatt/crypto.c:32:
./src/shared/util.h:240:9: warning: 1st function call argument is an uninitialized value

        return be32_to_cpu(get_unaligned((const uint32_t *) ptr));
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/shared/util.h:33:26: note: expanded from macro 'be32_to_cpu'
#define be32_to_cpu(val) bswap_32(val)
                         ^~~~~~~~~~~~~
/usr/include/byteswap.h:34:21: note: expanded from macro 'bswap_32'
#define bswap_32(x) __bswap_32 (x)
                    ^~~~~~~~~~~~~~
In file included from tools/mesh-gatt/crypto.c:32:
./src/shared/util.h:250:9: warning: 1st function call argument is an uninitialized value
        return be64_to_cpu(get_unaligned((const uint64_t *) ptr));
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/shared/util.h:34:26: note: expanded from macro 'be64_to_cpu'
#define be64_to_cpu(val) bswap_64(val)
                         ^~~~~~~~~~~~~
/usr/include/byteswap.h:37:21: note: expanded from macro 'bswap_64'
#define bswap_64(x) __bswap_64 (x)
                    ^~~~~~~~~~~~~~

2 warnings generated.

---
Regards,
Linux Bluetooth

#3 lore raw

PATCH v2 2/2 bap: Use util_iov_new when setting bcode

In reply to Vlad Pruteanu

Currently the broadcast code is set without memory being allocated for it resulting in segmentation fault. This fixes the issue by using the newly created util_iov_new that allocates the memory before setting it.

---
 profiles/audio/bap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
profiles/audio/bap.c +2 -3
index 53e7b3e34..e82a25382 100644
@@ -1042,9 +1042,8 @@ static void create_stream_for_bis(struct bap_data *bap_data,
 	setup->qos.bcast.framing = qos->bcast.framing;
 	setup->qos.bcast.encryption = qos->bcast.encryption;
 	if (setup->qos.bcast.encryption)
-		util_iov_append(setup->qos.bcast.bcode,
-				qos->bcast.bcode,
-				sizeof(qos->bcast.bcode));
+		setup->qos.bcast.bcode = util_iov_new(qos->bcast.bcode,
+						sizeof(qos->bcast.bcode));
 	setup->qos.bcast.options = qos->bcast.options;
 	setup->qos.bcast.skip = qos->bcast.skip;
 	setup->qos.bcast.sync_timeout = qos->bcast.sync_timeout;
Signature · 1 line
2.40.1
#4 lore raw
In reply to Vlad Pruteanu
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Wed, 19 Jun 2024 12:51:17 +0300 you wrote:

Currently the broadcast code is set without memory being allocated for it resulting in segmentation fault. This implements an util_iov_new function that allocates the memory before setting the user_data. The issue is fixed by using this function instead of util_iov_append.

Vlad Pruteanu (2):
shared/util: Add util_iov_new function
bap: Use util_iov_new when setting bcode

[...]

Here is the summary with links:
- [BlueZ,v2,1/2] shared/util: Add util_iov_new function

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=503ecbc655c5
  - [BlueZ,v2,2/2] bap: Use util_iov_new when setting bcode
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5ec05848a9d4

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html