shared/util: Add iovec helpers
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/4 shared/util: Add iovec helpers
From: Luiz Augusto von Dentz <[email protected]>
This adds iovec helpers functions.
--- src/shared/util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/util.h | 6 ++++++ 2 files changed, 59 insertions(+)
src/shared/util.c +53 -0
@@ -189,6 +189,59 @@ void util_clear_uid(uint64_t *bitmap, uint8_t id) *bitmap &= ~(((uint64_t )1 ) << (id -1 )); } +struct iovec *util_iov_dup (const struct iovec *iov,size_t cnt) +{ +struct iovec *dup; +size_t i; + +if (!iov) +return NULL ; + + dup = new0(struct iovec, cnt); + +for (i =0 ; i < cnt; i++) +util_iov_memcpy (&dup[i], iov[i].iov_base, iov[i].iov_len); + +return dup; +} + +int util_iov_memcmp (const struct iovec *iov1,const struct iovec *iov2) +{ +if (!iov1) +return 1 ; + +if (!iov2) +return -1 ; + +if (iov1->iov_len != iov2->iov_len) +return iov1->iov_len - iov2->iov_len; + +return memcmp (iov1->iov_base, iov2->iov_base, iov1->iov_len); +} + +void util_iov_memcpy (struct iovec *iov,void *src,size_t len) +{ +if (!iov) +return ; + + iov->iov_base =realloc (iov->iov_base, len); + iov->iov_len = len; +memcpy (iov->iov_base, src, len); +} + +void util_iov_free (struct iovec *iov,size_t cnt) +{ +size_t i; + +if (!iov) +return ; + +for (i =0 ; i < cnt; i++) +free (iov[i].iov_base); + +free (iov); +} + static const struct { uint16_t uuid; const char *str;
src/shared/util.h +6 -0
@@ -15,6 +15,7 @@#include <byteswap.h> #include <string.h> #include <sys/types.h> +#include <sys/uio.h> #define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]))#define BIT (n) (1 << (n))
@@ -109,6 +110,11 @@ ssize_t util_getrandom(void *buf, size_t buflen, unsigned int flags);uint8_t util_get_uid (uint64_t *bitmap,uint8_t max);void util_clear_uid (uint64_t *bitmap,uint8_t id); +struct iovec *util_iov_dup (const struct iovec *iov,size_t cnt); +int util_iov_memcmp (const struct iovec *iov1,const struct iovec *iov2); +void util_iov_memcpy (struct iovec *iov,void *src,size_t len); +void util_iov_free (struct iovec *iov,size_t cnt); +const char *bt_uuid16_to_str (uint16_t uuid);const char *bt_uuid32_to_str (uint32_t uuid);const char *bt_uuid128_to_str (const uint8_t uuid[16 ]);
Signature · 1 line
2.37.3
Luiz Augusto von Dentz
maintainerPATCH 2/4 shared/tester: Add tester_io_set_complete_func
From: Luiz Augusto von Dentz <[email protected]>
This adds tester_io_set_complete_func which can be used to set a callback when all iovec has been sent/received.
--- src/shared/tester.c | 16 ++++++++++++++++ src/shared/tester.h | 1 + 2 files changed, 17 insertions(+)
src/shared/tester.c +16 -0
@@ -89,6 +89,7 @@ struct test_case {tester_data_func_t test_func;tester_data_func_t teardown_func;tester_data_func_t post_teardown_func; +tester_data_func_t io_complete_func;gdouble start_time;gdouble end_time;unsigned int timeout;
@@ -913,6 +914,9 @@ static bool test_io_send(struct io *io, void *user_data) g_assert_cmpint(len, ==, iov->iov_len); +if (!test->iovcnt && test->io_complete_func) + test->io_complete_func (test->test_data); +return false; }
@@ -937,10 +941,15 @@ static bool test_io_recv(struct io *io, void *user_data) g_assert_cmpint(len, ==, iov->iov_len); +if (memcmp (buf, iov->iov_base, len)) +tester_monitor ('!' ,0x0004 ,0x0000 , iov->iov_base, len); +g_assert (memcmp (buf, iov->iov_base, len) ==0 );if (test->iovcnt)io_set_write_handler (io, test_io_send,NULL ,NULL ); +else if (test->io_complete_func) + test->io_complete_func (test->test_data);return true; }
@@ -1004,6 +1013,13 @@ void tester_io_send(void)io_set_write_handler (ios[1 ], test_io_send,NULL ,NULL ); } +void tester_io_set_complete_func (tester_data_func_t func) +{ +struct test_case *test =tester_get_test (); + + test->io_complete_func = func; +} +int tester_run (void ) {int ret;
src/shared/tester.h +1 -0
@@ -78,3 +78,4 @@ void tester_wait(unsigned int seconds, tester_wait_func_t func,struct io *tester_setup_io (const struct iovec *iov,int iovcnt);void tester_io_send (void ); +void tester_io_set_complete_func (tester_data_func_t func);
Signature · 1 line
2.37.3
Luiz Augusto von Dentz
maintainerPATCH 3/4 shared/bap: Fix crash when canceling requests
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
If bt_bap_unref/bap_free is called while there is an ongoing pending request it may endup calling into bap_notify_ready which will try to notify ready callbacks while holding a reference, but in case the reference is already 0 that means it would switch to 1 and back 0 causing a double free.
To prevent that bap_notify_ready now checks that the reference is not 0 with use of bt_bap_ref_safe.
--- src/shared/bap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
src/shared/bap.c +10 -1
@@ -2721,6 +2721,14 @@ struct bt_bap *bt_bap_ref(struct bt_bap *bap)return bap; } +static struct bt_bap *bt_bap_ref_safe (struct bt_bap *bap) +{ +if (!bap || !bap->ref_count) +return NULL ; + +return bt_bap_ref (bap); +} +void bt_bap_unref (struct bt_bap *bap) {if (!bap)
@@ -2739,7 +2747,8 @@ static void bap_notify_ready(struct bt_bap *bap)if (!queue_isempty (bap->pending))return ; -bt_bap_ref (bap); +if (!bt_bap_ref_safe (bap)) +return ;for (entry =queue_get_entries (bap->ready_cbs); entry; entry = entry->next) {
Signature · 1 line
2.37.3
Luiz Augusto von Dentz
maintainerPATCH 4/4 unit: Introduce test-bap
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Test Summary
------------
BAP/UCL/DISC/BV-01-C Passed BAP/UCL/DISC/BV-02-C Passed BAP/UCL/DISC/BV-06-C Passed BAP/UCL/DISC/BV-05-C Passed Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0 --- Makefile.am | 6 + unit/test-bap.c | 488 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 494 insertions(+) create mode 100644 unit/test-bap.c
Makefile.am +6 -0
@@ -569,6 +569,12 @@ unit_test_gattrib_LDADD = lib/libbluetooth-internal.la \ src/libshared-glib.la \ $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt +unit_tests += unit/test-bap + +unit_test_bap_SOURCES = unit/test-bap.c +unit_test_bap_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + if MIDI unit_tests += unit/test-midi unit_test_midi_CPPFLAGS = $(AM_CPPFLAGS) $(ALSA_CFLAGS) -DMIDI_TEST
unit/test-bap.c new file +488 -0
488 lines not on this page · raw message
Signature · 1 line
2.37.3
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=693816
---Test result---
Test Summary:
CheckPatch PASS 6.33 seconds GitLint PASS 4.08 seconds Prep - Setup ELL PASS 28.02 seconds Build - Prep PASS 0.82 seconds Build - Configure PASS 9.02 seconds Build - Make PASS 878.85 seconds Make Check PASS 11.77 seconds Make Check w/Valgrind PASS 297.61 seconds Make Distcheck PASS 244.45 seconds Build w/ext ELL - Configure PASS 9.06 seconds Build w/ext ELL - Make PASS 86.87 seconds Incremental Build w/ patches PASS 411.79 seconds Scan Build WARNING 1200.99 seconds
Details
##############################
Test: Scan Build - WARNING
Desc: Run Scan Build with patches
Output:
*****************************************************************************
The bugs reported by the scan-build may or may not be caused by your patches. Please check the list and fix the bugs if they are caused by your patch.
*****************************************************************************
In file included from tools/mesh-gatt/crypto.c:32:./src/shared/util.h:165:9: warning: 1st function call argument is an uninitialized value
return be32_to_cpu(get_unaligned((const uint32_t *) ptr));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/shared/util.h:31: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:175:9: warning: 1st function call argument is an uninitialized value
return be64_to_cpu(get_unaligned((const uint64_t *) ptr));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./src/shared/util.h:32: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
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 7 lines · On Wed, 9 Nov 2022 14:29:44 -0800 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
This adds iovec helpers functions.
--- src/shared/util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/util.h | 6 ++++++ 2 files changed, 59 insertions(+)
Here is the summary with links:
- [BlueZ,1/4] shared/util: Add iovec helpers
(no matching commit)
- [BlueZ,2/4] shared/tester: Add tester_io_set_complete_func
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=918c73acb778 - [BlueZ,3/4] shared/bap: Fix crash when canceling requests https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7fcd6889fb13
- [BlueZ,4/4] unit: Introduce test-bap
(no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html