device: use empty string as drvname when devicetree label is absent

As we move to making the `label` property optional, we need to account
for widespread use of `dev->name` in contexts where the pointer is not
validated before it is dereferenced.  Use an empty string instead of a
null pointer when no label is provided.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2021-02-12 08:04:09 -06:00 committed by Kumar Gala
commit 28897df295
3 changed files with 3 additions and 3 deletions

View file

@ -170,7 +170,7 @@ extern "C" {
#define DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn, \
data_ptr, cfg_ptr, level, prio, api_ptr) \
Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
DT_PROP_OR(node_id, label, NULL), init_fn, \
DT_PROP_OR(node_id, label, ""), init_fn, \
pm_control_fn, \
data_ptr, cfg_ptr, level, prio, api_ptr)

View file

@ -712,7 +712,7 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn, data, \
cfg, prio, api, mtu) \
Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
DT_PROP_OR(node_id, label, NULL), \
DT_PROP_OR(node_id, label, ""), \
init_fn, pm_control_fn, data, cfg, prio, \
api, mtu)

View file

@ -2269,7 +2269,7 @@ struct net_if_api {
#define NET_DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn, data, cfg, \
prio, api, l2, l2_ctx_type, mtu) \
Z_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
DT_PROP_OR(node_id, label, NULL), init_fn, \
DT_PROP_OR(node_id, label, ""), init_fn, \
pm_control_fn, data, cfg, prio, api, l2, \
l2_ctx_type, mtu)