DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: Add the check for null peer pointer in mp request handler
@ 2018-12-05  6:19 gfree.wind
  2018-12-10 16:41 ` Burakov, Anatoly
  0 siblings, 1 reply; 3+ messages in thread
From: gfree.wind @ 2018-12-05  6:19 UTC (permalink / raw)
  To: dev; +Cc: Gao Feng

From: Gao Feng <davidfgao@tencent.com>

Add the check for null peer pointer like the bundle pointer in the mp request
handler. They should follow same style. And add some logs for nomem cases.

Signed-off-by: Gao Feng <davidfgao@tencent.com>
---
 lib/librte_eal/common/hotplug_mp.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/librte_eal/common/hotplug_mp.c b/lib/librte_eal/common/hotplug_mp.c
index 070e2e0..0d2996f 100644
--- a/lib/librte_eal/common/hotplug_mp.c
+++ b/lib/librte_eal/common/hotplug_mp.c
@@ -200,6 +200,11 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
 	 * when it is ready.
 	 */
 	bundle->peer = strdup(peer);
+	if (bundle->peer == NULL) {
+		free(bundle);
+		RTE_LOG(ERR, EAL, "not enough memory\n");
+		return send_response_to_secondary(req, -ENOMEM, peer);
+	}
 
 	/**
 	 * We are at IPC callback thread, sync IPC is not allowed due to
@@ -311,6 +316,7 @@ static void __handle_primary_request(void *param)
 
 	bundle = calloc(1, sizeof(*bundle));
 	if (bundle == NULL) {
+		RTE_LOG(ERR, EAL, "not enough memory\n");
 		resp->result = -ENOMEM;
 		ret = rte_mp_reply(&mp_resp, peer);
 		if (ret)
@@ -325,6 +331,15 @@ static void __handle_primary_request(void *param)
 	 * when it is ready.
 	 */
 	bundle->peer = (void *)strdup(peer);
+	if (bundle->peer == NULL) {
+		RTE_LOG(ERR, EAL, "not enough memory\n");
+		free(bundle);
+		resp->result = -ENOMEM;
+		ret = rte_mp_reply(&mp_resp, peer);
+		if (ret)
+			RTE_LOG(ERR, EAL, "failed to send reply to primary request\n");
+		return ret;
+	}
 
 	/**
 	 * We are at IPC callback thread, sync IPC is not allowed due to
-- 
1.8.3.1

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

* Re: [dpdk-dev] [PATCH] eal: Add the check for null peer pointer in mp request handler
  2018-12-05  6:19 [dpdk-dev] [PATCH] eal: Add the check for null peer pointer in mp request handler gfree.wind
@ 2018-12-10 16:41 ` Burakov, Anatoly
  2018-12-19 22:45   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Burakov, Anatoly @ 2018-12-10 16:41 UTC (permalink / raw)
  To: gfree.wind, dev; +Cc: Gao Feng

On 05-Dec-18 6:19 AM, gfree.wind@vip.163.com wrote:
> From: Gao Feng <davidfgao@tencent.com>
> 
> Add the check for null peer pointer like the bundle pointer in the mp request
> handler. They should follow same style. And add some logs for nomem cases.
> 
> Signed-off-by: Gao Feng <davidfgao@tencent.com>
> ---
>   lib/librte_eal/common/hotplug_mp.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
> 
> diff --git a/lib/librte_eal/common/hotplug_mp.c b/lib/librte_eal/common/hotplug_mp.c
> index 070e2e0..0d2996f 100644
> --- a/lib/librte_eal/common/hotplug_mp.c
> +++ b/lib/librte_eal/common/hotplug_mp.c
> @@ -200,6 +200,11 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
>   	 * when it is ready.
>   	 */
>   	bundle->peer = strdup(peer);
> +	if (bundle->peer == NULL) {
> +		free(bundle);
> +		RTE_LOG(ERR, EAL, "not enough memory\n");

The error should probably be more descriptive (as in, it should be 
easier to identify where it came from). Suggested rewording:

"hotplug: cannot allocate memory for bundle"

or something along those lines. Same for other log messages.

As for actual code,

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>


> +		return send_response_to_secondary(req, -ENOMEM, peer);
> +	}
>   
>   	/**
>   	 * We are at IPC callback thread, sync IPC is not allowed due to
> @@ -311,6 +316,7 @@ static void __handle_primary_request(void *param)
>   
>   	bundle = calloc(1, sizeof(*bundle));
>   	if (bundle == NULL) {
> +		RTE_LOG(ERR, EAL, "not enough memory\n"); >   		resp->result = -ENOMEM;
>   		ret = rte_mp_reply(&mp_resp, peer);
>   		if (ret)
> @@ -325,6 +331,15 @@ static void __handle_primary_request(void *param)
>   	 * when it is ready.
>   	 */
>   	bundle->peer = (void *)strdup(peer);
> +	if (bundle->peer == NULL) {
> +		RTE_LOG(ERR, EAL, "not enough memory\n");
> +		free(bundle);
> +		resp->result = -ENOMEM;
> +		ret = rte_mp_reply(&mp_resp, peer);
> +		if (ret)
> +			RTE_LOG(ERR, EAL, "failed to send reply to primary request\n");
> +		return ret;
> +	}
>   
>   	/**
>   	 * We are at IPC callback thread, sync IPC is not allowed due to
> 


-- 
Thanks,
Anatoly

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

* Re: [dpdk-dev] [PATCH] eal: Add the check for null peer pointer in mp request handler
  2018-12-10 16:41 ` Burakov, Anatoly
@ 2018-12-19 22:45   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2018-12-19 22:45 UTC (permalink / raw)
  To: Gao Feng; +Cc: dev, Burakov, Anatoly, gfree.wind

10/12/2018 17:41, Burakov, Anatoly:
> On 05-Dec-18 6:19 AM, gfree.wind@vip.163.com wrote:
> > From: Gao Feng <davidfgao@tencent.com>
> > 
> > Add the check for null peer pointer like the bundle pointer in the mp request
> > handler. They should follow same style. And add some logs for nomem cases.
> > 
> > Signed-off-by: Gao Feng <davidfgao@tencent.com>
> > ---
> >   lib/librte_eal/common/hotplug_mp.c | 15 +++++++++++++++
> >   1 file changed, 15 insertions(+)
> > 
> > diff --git a/lib/librte_eal/common/hotplug_mp.c b/lib/librte_eal/common/hotplug_mp.c
> > index 070e2e0..0d2996f 100644
> > --- a/lib/librte_eal/common/hotplug_mp.c
> > +++ b/lib/librte_eal/common/hotplug_mp.c
> > @@ -200,6 +200,11 @@ static int cmp_dev_name(const struct rte_device *dev, const void *_name)
> >   	 * when it is ready.
> >   	 */
> >   	bundle->peer = strdup(peer);
> > +	if (bundle->peer == NULL) {
> > +		free(bundle);
> > +		RTE_LOG(ERR, EAL, "not enough memory\n");
> 
> The error should probably be more descriptive (as in, it should be 
> easier to identify where it came from). Suggested rewording:
> 
> "hotplug: cannot allocate memory for bundle"
> 
> or something along those lines. Same for other log messages.
> 
> As for actual code,
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks

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

end of thread, other threads:[~2018-12-19 22:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05  6:19 [dpdk-dev] [PATCH] eal: Add the check for null peer pointer in mp request handler gfree.wind
2018-12-10 16:41 ` Burakov, Anatoly
2018-12-19 22:45   ` Thomas Monjalon

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).