Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH] peer: Add memory allocation controls (Jose Blanquicet)
   2. Re: [PATCH] peer: Add memory allocation controls
      (Tomasz Bursztyka)
   3. [PATCH v2] peer: Add memory allocation controls (Jose Blanquicet)
   4. Re: [PATCH] peer: Add memory allocation controls (Jose Blanquicet)
   5. Re: [PATCH] peer: Add memory allocation controls
      (Tomasz Bursztyka)
   6. Re: [PATCH] peer: Add memory allocation controls (Jose Blanquicet)
   7. Re: Unable To Get DHCP for Wired Network (Lad, Prabhakar)
   8. Re: [PATCH] peer: Add memory allocation controls (Slava Monich)


----------------------------------------------------------------------

Message: 1
Date: Wed,  7 Dec 2016 10:00:28 +0000
From: Jose Blanquicet <[email protected]>
To: [email protected]
Subject: [PATCH] peer: Add memory allocation controls
Message-ID:
        
<1481104828-23846-1-git-send-email-jose.blanquicet-melen...@magnetimarelli.com>
        

Add control where pointer may be NULL and use g_try_new0 instead of g_malloc0 in
order to avoid potential abortion on failure.

---
 plugins/wifi.c |  3 +++
 src/peer.c     | 19 ++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index a8cb7ca..aaacafa 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -3274,6 +3274,9 @@ static void peer_found(GSupplicantPeer *peer)
                return;
 
        connman_peer = connman_peer_create(identifier);
+       if (!connman_peer)
+               return NULL;
+
        connman_peer_set_name(connman_peer, name);
        connman_peer_set_device(connman_peer, wifi->device);
        apply_peer_services(peer, connman_peer);
diff --git a/src/peer.c b/src/peer.c
index ddd85f2..0ed8d9b 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -761,7 +761,10 @@ struct connman_peer *connman_peer_create(const char 
*identifier)
 {
        struct connman_peer *peer;
 
-       peer = g_malloc0(sizeof(struct connman_peer));
+       peer = g_try_new0(struct connman_peer, 1);
+       if (!peer)
+               return NULL;
+
        peer->identifier = g_strdup(identifier);
        peer->state = CONNMAN_PEER_STATE_IDLE;
 
@@ -1033,7 +1036,10 @@ void connman_peer_add_service(struct connman_peer *peer,
        if (!peer || !data || type == CONNMAN_PEER_SERVICE_UNKNOWN)
                return;
 
-       service = g_malloc0(sizeof(struct _peer_service));
+       service = g_try_new0(struct _peer_service, 1);
+       if (!service)
+               return;
+
        service->type = type;
        service->data = g_memdup(data, data_length * sizeof(unsigned char));
        service->length = data_length;
@@ -1072,6 +1078,8 @@ static void peer_ip_bound(struct connman_ipconfig 
*ipconfig,
                                                        const char *ifname)
 {
        struct connman_peer *peer = __connman_ipconfig_get_data(ipconfig);
+       if (!peer)
+               return;
 
        DBG("%s ip bound", ifname);
 
@@ -1084,6 +1092,8 @@ static void peer_ip_release(struct connman_ipconfig 
*ipconfig,
                                                        const char *ifname)
 {
        struct connman_peer *peer = __connman_ipconfig_get_data(ipconfig);
+       if (!peer)
+               return;
 
        DBG("%s ip release", ifname);
 
@@ -1246,7 +1256,10 @@ int __connman_peer_init(void)
        peers_table = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                        NULL, peer_free);
 
-       peers_notify = g_new0(struct _peers_notify, 1);
+       peers_notify = g_try_new0(struct _peers_notify, 1);
+       if (!peers_notify)
+               return -ENOMEM;
+
        peers_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
        peers_notify->remove = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                                g_free, NULL);
-- 
1.9.1



------------------------------

Message: 2
Date: Wed, 7 Dec 2016 11:11:09 +0100
From: Tomasz Bursztyka <[email protected]>
To: [email protected]
Subject: Re: [PATCH] peer: Add memory allocation controls
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Hi Jose,

I thought the rule was that if a tiny allocation fails, it means we are 
in a deep trouble
so it should abort.

@wagi: has this rule changed?

Tomasz


------------------------------

Message: 3
Date: Wed,  7 Dec 2016 10:24:30 +0000
From: Jose Blanquicet <[email protected]>
To: [email protected]
Subject: [PATCH v2] peer: Add memory allocation controls
Message-ID:
        
<1481106270-29834-1-git-send-email-jose.blanquicet-melen...@magnetimarelli.com>
        

Add control where pointer may be NULL and use g_try_new0 instead of g_malloc0 in
order to avoid potential abortion on failure.

---
 plugins/wifi.c |  3 +++
 src/peer.c     | 19 ++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index 70cec77..2af41de 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -2853,6 +2853,9 @@ static void peer_found(GSupplicantPeer *peer)
                return;
 
        connman_peer = connman_peer_create(identifier);
+       if (!connman_peer)
+               return;
+
        connman_peer_set_name(connman_peer, name);
        connman_peer_set_device(connman_peer, wifi->device);
        apply_peer_services(peer, connman_peer);
diff --git a/src/peer.c b/src/peer.c
index ad4e445..6b712aa 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -706,7 +706,10 @@ struct connman_peer *connman_peer_create(const char 
*identifier)
 {
        struct connman_peer *peer;
 
-       peer = g_malloc0(sizeof(struct connman_peer));
+       peer = g_try_new0(struct connman_peer, 1);
+       if (!peer)
+               return NULL;
+
        peer->identifier = g_strdup(identifier);
        peer->state = CONNMAN_PEER_STATE_IDLE;
 
@@ -978,7 +981,10 @@ void connman_peer_add_service(struct connman_peer *peer,
        if (!peer || !data || type == CONNMAN_PEER_SERVICE_UNKNOWN)
                return;
 
-       service = g_malloc0(sizeof(struct _peer_service));
+       service = g_try_new0(struct _peer_service, 1);
+       if (!service)
+               return;
+
        service->type = type;
        service->data = g_memdup(data, data_length * sizeof(unsigned char));
        service->length = data_length;
@@ -1017,6 +1023,8 @@ static void peer_ip_bound(struct connman_ipconfig 
*ipconfig,
                                                        const char *ifname)
 {
        struct connman_peer *peer = __connman_ipconfig_get_data(ipconfig);
+       if (!peer)
+               return;
 
        DBG("%s ip bound", ifname);
 
@@ -1029,6 +1037,8 @@ static void peer_ip_release(struct connman_ipconfig 
*ipconfig,
                                                        const char *ifname)
 {
        struct connman_peer *peer = __connman_ipconfig_get_data(ipconfig);
+       if (!peer)
+               return;
 
        DBG("%s ip release", ifname);
 
@@ -1186,7 +1196,10 @@ int __connman_peer_init(void)
        peers_table = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                        NULL, peer_free);
 
-       peers_notify = g_new0(struct _peers_notify, 1);
+       peers_notify = g_try_new0(struct _peers_notify, 1);
+       if (!peers_notify)
+               return -ENOMEM;
+
        peers_notify->add = g_hash_table_new(g_str_hash, g_str_equal);
        peers_notify->remove = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                                g_free, NULL);
-- 
1.9.1



------------------------------

Message: 4
Date: Wed, 7 Dec 2016 11:48:08 +0100
From: Jose Blanquicet <[email protected]>
To: Tomasz Bursztyka <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] peer: Add memory allocation controls
Message-ID:
        <cafc8ij+j+mnry4ip+vx4gxpmd8ub8man13-+6f-rgeddt-d...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Tomasz,

> I thought the rule was that if a tiny allocation fails, it means we are in a
> deep trouble
> so it should abort.

I am not sure I got your point. I just put this because according to
GLib documentation g_malloc0() aborts the program on failure but
instead you are telling that this is a desired behaviour? You want to
abort ConnMan in such a case?

Cheers,

Jose Blanquicet


------------------------------

Message: 5
Date: Wed, 7 Dec 2016 11:59:21 +0100
From: Tomasz Bursztyka <[email protected]>
To: Jose Blanquicet <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] peer: Add memory allocation controls
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed

Hi Jose,
>
>> I thought the rule was that if a tiny allocation fails, it means we are in a
>> deep trouble
>> so it should abort.
> I am not sure I got your point. I just put this because according to
> GLib documentation g_malloc0() aborts the program on failure but
> instead you are telling that this is a desired behaviour? You want to
> abort ConnMan in such a case?

Yes, thus why g_malloc0() has been used. It was made on purpose.

Tomasz


------------------------------

Message: 6
Date: Wed, 7 Dec 2016 12:08:56 +0100
From: Jose Blanquicet <[email protected]>
To: Tomasz Bursztyka <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] peer: Add memory allocation controls
Message-ID:
        <CAFC8iJ+6q+9W7fr8Ke_0shO=lvyy-pi8-kgzeddcakluff_...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Tomasz,

>>> I thought the rule was that if a tiny allocation fails, it means we are
>>> in a
>>> deep trouble
>>> so it should abort.
>>
>> I am not sure I got your point. I just put this because according to
>> GLib documentation g_malloc0() aborts the program on failure but
>> instead you are telling that this is a desired behaviour? You want to
>> abort ConnMan in such a case?
>
>
> Yes, thus why g_malloc0() has been used. It was made on purpose.

Understood. But of course you only mean in initialization functions
__connman_{service|peer ...}_init(), right? If so, I agree thus let's
forget that patch.

Thanks for the clarification.

Jose


------------------------------

Message: 7
Date: Wed, 7 Dec 2016 11:33:47 +0000
From: "Lad, Prabhakar" <[email protected]>
To: Robert Tiemann <[email protected]>
Cc: [email protected]
Subject: Re: Unable To Get DHCP for Wired Network
Message-ID:
        <CA+V-a8vaFv1Qobd=sgoqnt+ksgo7qwsnrnv78nj9h0xhjzo...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Robert,

On Tue, Dec 6, 2016 at 3:45 PM, Robert Tiemann <[email protected]> wrote:
>
> On 12/06/2016 03:48 PM, Lad, Prabhakar wrote:
>
>>> Other than that I'd guess there might be something wrong with the DHCP 
>>> server
>>> setup. Can you check its log?
>>>
>> I am not sure what you meant here, isnt dhcp part of connman ?
>
> I think you are trying to use ConnMan as a DHCP client to configure
> the network interface of your device. This client is part of ConnMan,
> and it needs to connect to some DHCP server to obtain an IP address (a
> lease) and related configuration.
>
> The DHCP server usually runs on some server or router. If no DHCP
> server can be discovered on your network, then you'll get a link-local
> address in block 169.254.0.0/16, which is probably useless for you.
> According to your log, a DHCP client request was started at 00:00:08,
> and it timed out 30 seconds later at 00:00:38. Ten seconds later, you
> got address 169.254.47.3 as a fallback.
>
> So there seems to be no DHCP server on your network. In this case you
> need to enable the DHCP server on some device on your network, or use
> manual IP configuration without DHCP. If you know there is a DHCP
> server, then you should read its log to find out if perhaps your DHCP
> client request got filtered out.
>
> (As I just found out, there is also a DHCP server inside ConnMan, but
> it seems not to be useful for this use case.)
>
Got it working, eventually it turned out to be hardware issue, thanks
for your support.

Cheers,
--Prabhakar Lad


------------------------------

Message: 8
Date: Wed, 7 Dec 2016 14:08:23 +0200
From: Slava Monich <[email protected]>
To: [email protected]
Subject: Re: [PATCH] peer: Add memory allocation controls
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

> Hi Tomasz,
>
>>>> I thought the rule was that if a tiny allocation fails, it means we are
>>>> in a
>>>> deep trouble
>>>> so it should abort.
>>> I am not sure I got your point. I just put this because according to
>>> GLib documentation g_malloc0() aborts the program on failure but
>>> instead you are telling that this is a desired behaviour? You want to
>>> abort ConnMan in such a case?
>>
>> Yes, thus why g_malloc0() has been used. It was made on purpose.
> Understood. But of course you only mean in initialization functions
> __connman_{service|peer ...}_init(), right? If so, I agree thus let's
> forget that patch.
>
> Thanks for the clarification.
>
> Jose


One should also keep in mind that (probably) most Linux systems these 
days are configured to use overcommit, meaning that malloc never fails 
(except when you run out of the virtual address space). Basically it 
only reserves the virtual address range. Those pages are not initially 
backed by anything, the actual allocation is happening on the 
page-by-page basis when the program accesses the page for the first time.

Not to mention that out of memory conditions should be handled 
everywhere in the program (and all the libraries it's using) or nowhere. 
Occasional OOM checks make very little sense.

Cheers,
-Slava


------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 14, Issue 10
***************************************

Reply via email to