net/cnxk: fix dangling pointer in meter for gcc12
PATCH 1/1 net/cnxk: fix dangling pointer in meter for gcc12
Observed with: gcc (GCC) 12.0.0 20220116 (experimental)
In file included from ../drivers/net/cnxk/cnxk_ethdev.h:16,
from ../drivers/net/cnxk/cnxk_ethdev_mtr.c:5:
In function ‘rte_mtr_error_set’,
inlined from ‘cnxk_nix_mtr_policy_validate’ at ../drivers/net/cnxk/cnxk_ethdev_mtr.c:311:14:
../lib/ethdev/rte_mtr_driver.h:188:24: error: storing the address of local variable ‘message’ in ‘*error.message’ [-Werror=dangling-pointer=]
188 | *error = (struct rte_mtr_error){
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
189 | .type = type,
| ~~~~~~~~~~~~~
190 | .cause = cause,
| ~~~~~~~~~~~~~~~
191 | .message = message,
| ~~~~~~~~~~~~~~~~~~~
192 | };
| ~
../drivers/net/cnxk/cnxk_ethdev_mtr.c: In function ‘cnxk_nix_mtr_policy_validate’:
../drivers/net/cnxk/cnxk_ethdev_mtr.c:288:14: note: ‘message’ declared here
288 | char message[1024];
| ^~~~~~~../drivers/net/cnxk/cnxk_ethdev_mtr.c:288:14: note: ‘error’ declared here
It is a valid compiler warning, make local variable a global one.
---
Fix is done in a quickest way, mainly to report the issue, please feel free to suggest another solution for the build error.
--- drivers/net/cnxk/cnxk_ethdev_mtr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/cnxk/cnxk_ethdev_mtr.c +1 -1
@@ -285,7 +285,7 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,static const char *const action_color[] = {"Green" ,"Yellow" ,"Red" };bool supported[RTE_COLORS ] = {false, false, false};const struct rte_flow_action *action; -char message[1024 ]; +static char message[1024 ];uint32_t i;RTE_SET_USED (dev);
Signature · 1 line
2.34.1
PATCH 1/1 net/cnxk: fix compilation issue for gcc12
resolve compilation error caused due to gcc 12 version
error: storing the address of local variable message in *error.message
--- drivers/net/cnxk/cnxk_ethdev_mtr.c | 59 ++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/net/cnxk/cnxk_ethdev_mtr.c +44 -15
@@ -285,15 +285,54 @@ cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,return 0 ; } +static int +update_mtr_err (uint32_t act_color,struct rte_mtr_error *error,bool action) +{ +const char *str; +switch (act_color) { +case RTE_COLOR_GREEN : +if (action) { + str ="Green action is not valid" ; + goto notsup; + }else { + str ="Green action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_YELLOW : +if (action) { + str ="Yellow action is not valid" ; + goto notsup; + }else { + str ="Yellow action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_RED : +if (action) { + str ="Red action is not valid" ; + goto notsup; + }else { + str ="Red action is null" ; + goto notvalid; + } +break ; + } +notsup: +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +notvalid: +return -rte_mtr_error_set (error,EINVAL , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +} +static int cnxk_nix_mtr_policy_validate (struct rte_eth_dev *dev,struct rte_mtr_meter_policy_params *policy,struct rte_mtr_error *error) { -static const char *const action_color[] = {"Green" ,"Yellow" ,"Red" };bool supported[RTE_COLORS ] = {false, false, false};const struct rte_flow_action *action; -char message[1024 ];uint32_t i;RTE_SET_USED (dev);
@@ -315,21 +354,11 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,if (action->type ==RTE_FLOW_ACTION_TYPE_VOID ) supported[i] = true; -if (!supported[i]) { -sprintf (message, -"%s action is not valid" , - action_color[i]); -return -rte_mtr_error_set (error, -ENOTSUP , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); - } +if (!supported[i]) +return update_mtr_err (i, error, true); } }else { -sprintf (message,"%s action is null" , action_color[i]); -return -rte_mtr_error_set (error,EINVAL , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); +return update_mtr_err (i, error, false); } }
Signature · 1 line
2.25.1
Re: [PATCH] net/cnxk: fix compilation issue for gcc12
Quoted 8 lines · Rakesh Kudurumalla
resolve compilation error caused due to gcc 12 version
error: storing the address of local variable message in *error.messageFixes 26b034f78ca7 ("net/cnxk: support to validate meter policy")
Quoted 94 lines
Signed-off-by Rakesh Kudurumalla <[email protected]>--- drivers/net/cnxk/cnxk_ethdev_mtr.c | 59 ++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 15 deletions(-)drivers/net/cnxk/cnxk_ethdev_mtr.c +44
-16@@ -285,15 +285,54 @@ cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,return 0 ; } +static int +update_mtr_err (uint32_t act_color,struct rte_mtr_error *error,bool action) +{ +const char *str; +switch (act_color) { +case RTE_COLOR_GREEN : +if (action) { + str ="Green action is not valid" ; + goto notsup; + }else { + str ="Green action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_YELLOW : +if (action) { + str ="Yellow action is not valid" ; + goto notsup; + }else { + str ="Yellow action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_RED : +if (action) { + str ="Red action is not valid" ; + goto notsup; + }else { + str ="Red action is null" ; + goto notvalid; + } +break ; + } +notsup: +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +notvalid: +return -rte_mtr_error_set (error,EINVAL , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +} +static int cnxk_nix_mtr_policy_validate (struct rte_eth_dev *dev,struct rte_mtr_meter_policy_params *policy,struct rte_mtr_error *error) { -static const char *const action_color[] = {"Green" ,"Yellow" ,"Red" };bool supported[RTE_COLORS ] = {false, false, false};const struct rte_flow_action *action; -char message[1024 ];uint32_t i;RTE_SET_USED (dev);@@ -315,21 +354,11 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,if (action->type ==RTE_FLOW_ACTION_TYPE_VOID ) supported[i] = true; -if (!supported[i]) { -sprintf (message, -"%s action is not valid" , - action_color[i]); -return -rte_mtr_error_set (error, -ENOTSUP , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); - } +if (!supported[i]) +return update_mtr_err (i, error, true); } }else { -sprintf (message,"%s action is null" , action_color[i]); -return -rte_mtr_error_set (error,EINVAL , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); +return update_mtr_err (i, error, false); } } --2.25.1
Re: [PATCH] net/cnxk: fix compilation issue for gcc12
Quoted 7 lines · Jerin Jacob
Quoted 4 lines · Rakesh Kudurumalla
resolve compilation error caused due to gcc 12 version
error: storing the address of local variable message in *error.message
Quoted 8 lines
Quoted 4 lines
Fixes 26b034f78ca7 ("net/cnxk: support to validate meter policy")Reported-By Ferruh Yigit <[email protected]>Quoted 1 line
Signed-off-by Rakesh Kudurumalla <[email protected]>
Updated the commit as follows and applied to
dpdk-next-net-mrvl/for-next-net. Thanks
net/cnxk: fix compilation issue with gcc12
Resolve following compilation error with gcc 12 version.
error: storing the address of local variable message in *error.message
Quoted 93 lines
Quoted 93 lines
--- drivers/net/cnxk/cnxk_ethdev_mtr.c | 59 ++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 15 deletions(-)drivers/net/cnxk/cnxk_ethdev_mtr.c +44
-16@@ -285,15 +285,54 @@ cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,return 0 ; } +static int +update_mtr_err (uint32_t act_color,struct rte_mtr_error *error,bool action) +{ +const char *str; +switch (act_color) { +case RTE_COLOR_GREEN : +if (action) { + str ="Green action is not valid" ; + goto notsup; + }else { + str ="Green action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_YELLOW : +if (action) { + str ="Yellow action is not valid" ; + goto notsup; + }else { + str ="Yellow action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_RED : +if (action) { + str ="Red action is not valid" ; + goto notsup; + }else { + str ="Red action is null" ; + goto notvalid; + } +break ; + } +notsup: +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +notvalid: +return -rte_mtr_error_set (error,EINVAL , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +} +static int cnxk_nix_mtr_policy_validate (struct rte_eth_dev *dev,struct rte_mtr_meter_policy_params *policy,struct rte_mtr_error *error) { -static const char *const action_color[] = {"Green" ,"Yellow" ,"Red" };bool supported[RTE_COLORS ] = {false, false, false};const struct rte_flow_action *action; -char message[1024 ];uint32_t i;RTE_SET_USED (dev);@@ -315,21 +354,11 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,if (action->type ==RTE_FLOW_ACTION_TYPE_VOID ) supported[i] = true; -if (!supported[i]) { -sprintf (message, -"%s action is not valid" , - action_color[i]); -return -rte_mtr_error_set (error, -ENOTSUP , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); - } +if (!supported[i]) +return update_mtr_err (i, error, true); } }else { -sprintf (message,"%s action is null" , action_color[i]); -return -rte_mtr_error_set (error,EINVAL , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); +return update_mtr_err (i, error, false); } } --2.25.1
PATCH 1/1 net/cnxk: fix compilation issue for gcc12
In reply to Ferruh Yigitresolve compilation error caused due to gcc 12 version
error: storing the address of local variable message in *error.message
---
v2 : removed changeid
drivers/net/cnxk/cnxk_ethdev_mtr.c | 59 ++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/net/cnxk/cnxk_ethdev_mtr.c +44 -15
@@ -285,15 +285,54 @@ cnxk_nix_mtr_profile_delete(struct rte_eth_dev *eth_dev, uint32_t profile_id,return 0 ; } +static int +update_mtr_err (uint32_t act_color,struct rte_mtr_error *error,bool action) +{ +const char *str; +switch (act_color) { +case RTE_COLOR_GREEN : +if (action) { + str ="Green action is not valid" ; + goto notsup; + }else { + str ="Green action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_YELLOW : +if (action) { + str ="Yellow action is not valid" ; + goto notsup; + }else { + str ="Yellow action is null" ; + goto notvalid; + } +break ; +case RTE_COLOR_RED : +if (action) { + str ="Red action is not valid" ; + goto notsup; + }else { + str ="Red action is null" ; + goto notvalid; + } +break ; + } +notsup: +return -rte_mtr_error_set (error,ENOTSUP , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +notvalid: +return -rte_mtr_error_set (error,EINVAL , +RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , str); +} +static int cnxk_nix_mtr_policy_validate (struct rte_eth_dev *dev,struct rte_mtr_meter_policy_params *policy,struct rte_mtr_error *error) { -static const char *const action_color[] = {"Green" ,"Yellow" ,"Red" };bool supported[RTE_COLORS ] = {false, false, false};const struct rte_flow_action *action; -char message[1024 ];uint32_t i;RTE_SET_USED (dev);
@@ -315,21 +354,11 @@ cnxk_nix_mtr_policy_validate(struct rte_eth_dev *dev,if (action->type ==RTE_FLOW_ACTION_TYPE_VOID ) supported[i] = true; -if (!supported[i]) { -sprintf (message, -"%s action is not valid" , - action_color[i]); -return -rte_mtr_error_set (error, -ENOTSUP , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); - } +if (!supported[i]) +return update_mtr_err (i, error, true); } }else { -sprintf (message,"%s action is null" , action_color[i]); -return -rte_mtr_error_set (error,EINVAL , -RTE_MTR_ERROR_TYPE_METER_POLICY ,NULL , - message); +return update_mtr_err (i, error, false); } }
Signature · 1 line
2.25.1