device: fix potential truncation of DT-derived device names

While using the encoded path to a device tree node guarantees a unique
identifier for the corresponding device there is a limit on the number
of characters of that name that can be captured when looking up a
device by name from user mode, and the path can exceed that limit.

Synthesize a unique name from the node dependency ordinal instead, and
update the gen_defines script to record the name associated with the
full path in the extern declaration.

Add a build-time check that no device is created with a name that
violates the user mode requirement.

Also update the network device DTS helper functions to use the same
inference for dev_name and label that the real one does, since they
bypass the real one.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2021-01-23 07:56:09 -06:00 committed by Anas Nashif
commit f91e9fba51
4 changed files with 25 additions and 9 deletions

View file

@ -2268,7 +2268,8 @@ 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, node_id, DT_LABEL(node_id), init_fn, \
Z_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
DT_PROP_OR(node_id, label, NULL), init_fn, \
pm_control_fn, data, cfg, prio, api, l2, \
l2_ctx_type, mtu)