All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/crypto: Transform bt_cryto in a singleton
@ 2021-01-15 19:02 Luiz Augusto von Dentz
  2021-01-15 19:15 ` [BlueZ] " bluez.test.bot
  0 siblings, 1 reply; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2021-01-15 19:02 UTC (permalink / raw)
  To: linux-bluetooth

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

This makes bt_crypto always return the same instance thus avoiding the
problem of having multiple PF sockets opened which may hit the file
descriptor limit.
---
 src/shared/crypto.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/shared/crypto.c b/src/shared/crypto.c
index 6d14903e4..d5efa416d 100644
--- a/src/shared/crypto.c
+++ b/src/shared/crypto.c
@@ -126,34 +126,40 @@ static int cmac_aes_setup(void)
 	return fd;
 }
 
+static struct bt_crypto *singleton;
+
 struct bt_crypto *bt_crypto_new(void)
 {
-	struct bt_crypto *crypto;
+	if (singleton)
+		return bt_crypto_ref(singleton);
 
-	crypto = new0(struct bt_crypto, 1);
+	singleton = new0(struct bt_crypto, 1);
 
-	crypto->ecb_aes = ecb_aes_setup();
-	if (crypto->ecb_aes < 0) {
-		free(crypto);
+	singleton->ecb_aes = ecb_aes_setup();
+	if (singleton->ecb_aes < 0) {
+		free(singleton);
+		singleton = NULL;
 		return NULL;
 	}
 
-	crypto->urandom = urandom_setup();
-	if (crypto->urandom < 0) {
-		close(crypto->ecb_aes);
-		free(crypto);
+	singleton->urandom = urandom_setup();
+	if (singleton->urandom < 0) {
+		close(singleton->ecb_aes);
+		free(singleton);
+		singleton = NULL;
 		return NULL;
 	}
 
-	crypto->cmac_aes = cmac_aes_setup();
-	if (crypto->cmac_aes < 0) {
-		close(crypto->urandom);
-		close(crypto->ecb_aes);
-		free(crypto);
+	singleton->cmac_aes = cmac_aes_setup();
+	if (singleton->cmac_aes < 0) {
+		close(singleton->urandom);
+		close(singleton->ecb_aes);
+		free(singleton);
+		singleton = NULL;
 		return NULL;
 	}
 
-	return bt_crypto_ref(crypto);
+	return bt_crypto_ref(singleton);
 }
 
 struct bt_crypto *bt_crypto_ref(struct bt_crypto *crypto)
@@ -179,6 +185,7 @@ void bt_crypto_unref(struct bt_crypto *crypto)
 	close(crypto->cmac_aes);
 
 	free(crypto);
+	singleton = NULL;
 }
 
 bool bt_crypto_random_bytes(struct bt_crypto *crypto,
-- 
2.26.2


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

* RE: [BlueZ] shared/crypto: Transform bt_cryto in a singleton
  2021-01-15 19:02 [PATCH BlueZ] shared/crypto: Transform bt_cryto in a singleton Luiz Augusto von Dentz
@ 2021-01-15 19:15 ` bluez.test.bot
  2021-01-15 19:56   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 3+ messages in thread
From: bluez.test.bot @ 2021-01-15 19:15 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

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=415727

---Test result---

##############################
Test: CheckPatch - PASS

##############################
Test: CheckGitLint - PASS

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS



---
Regards,
Linux Bluetooth


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

* Re: [BlueZ] shared/crypto: Transform bt_cryto in a singleton
  2021-01-15 19:15 ` [BlueZ] " bluez.test.bot
@ 2021-01-15 19:56   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2021-01-15 19:56 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Fri, Jan 15, 2021 at 11:15 AM <bluez.test.bot@gmail.com> wrote:
>
> 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=415727
>
> ---Test result---
>
> ##############################
> Test: CheckPatch - PASS
>
> ##############################
> Test: CheckGitLint - PASS
>
> ##############################
> Test: CheckBuild - PASS
>
> ##############################
> Test: MakeCheck - PASS
>
>
>
> ---
> Regards,
> Linux Bluetooth

Pushed.

-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2021-01-15 19:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 19:02 [PATCH BlueZ] shared/crypto: Transform bt_cryto in a singleton Luiz Augusto von Dentz
2021-01-15 19:15 ` [BlueZ] " bluez.test.bot
2021-01-15 19:56   ` Luiz Augusto von Dentz

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.