can: dev: add sanity check in can_set_static_ctrlmode()
Previous patch removed can_priv::ctrlmode_static to replace it with can_get_static_ctrlmode(). A condition sine qua non for this to work is that the controller static modes should never be set in can_priv::ctrlmode_supported (c.f. the comment on can_priv::ctrlmode_supported which states that it is for "options that can be *modified* by netlink"). Also, this condition is already correctly fulfilled by all existing drivers which rely on the ctrlmode_static feature. Nonetheless, we added an extra safeguard in can_set_static_ctrlmode() to return an error value and to warn the developer who would be adventurous enough to set to static a given feature that is already set to supported. The drivers which rely on the static controller mode are then updated to check the return value of can_set_static_ctrlmode(). Link: https://lore.kernel.org/all/20211213160226.56219-3-mailhol.vincent@wanadoo.fr Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
parent
c9e1d8ed30
commit
7d4a101c0b
3 changed files with 19 additions and 6 deletions
|
|
@ -131,17 +131,24 @@ static inline s32 can_get_relative_tdco(const struct can_priv *priv)
|
|||
}
|
||||
|
||||
/* helper to define static CAN controller features at device creation time */
|
||||
static inline void can_set_static_ctrlmode(struct net_device *dev,
|
||||
u32 static_mode)
|
||||
static inline int __must_check can_set_static_ctrlmode(struct net_device *dev,
|
||||
u32 static_mode)
|
||||
{
|
||||
struct can_priv *priv = netdev_priv(dev);
|
||||
|
||||
/* alloc_candev() succeeded => netdev_priv() is valid at this point */
|
||||
if (priv->ctrlmode_supported & static_mode) {
|
||||
netdev_warn(dev,
|
||||
"Controller features can not be supported and static at the same time\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
priv->ctrlmode = static_mode;
|
||||
|
||||
/* override MTU which was set by default in can_setup()? */
|
||||
if (static_mode & CAN_CTRLMODE_FD)
|
||||
dev->mtu = CANFD_MTU;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline u32 can_get_static_ctrlmode(struct can_priv *priv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue