Hmm, I am still not a fan of setting a mutex for a single concurrency
issue which can only happen during probing.
What about this:
static int __f81604_set_termination(struct net_device *netdev, u16 term)
{
struct f81604_port_priv *port_priv = netdev_priv(netdev);
u8 mask, data = 0;
if (netdev->dev_id == 0)
mask = F81604_CAN0_TERM;
else
mask = F81604_CAN1_TERM;
if (term == F81604_TERMINATION_ENABLED)
data = mask;
return f81604_mask_set_register(port_priv->dev, F81604_TERMINATOR_REG,
mask, data);
}
static int f81604_set_termination(struct net_device *netdev, u16 term)
{
ASSERT_RTNL();
return __f81604_set_termination(struct net_device *netdev, u16 term);
}
static int f81604_init_termination(struct f81604_priv *priv)
{
int i, ret;
for (i = 0; i < ARRAY_SIZE(f81604_priv->netdev); i++) {
ret = __f81604_set_termination(f81604_priv->netdev[i],
F81604_TERMINATION_DISABLED);
if (ret)
return ret;
}
}
static int f81604_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
/* ... */
err = f81604_init_termination(priv);
if (err)
goto failure_cleanup;
for (i = 0; i < ARRAY_SIZE(f81604_priv->netdev); i++) {
/* ... */
}
/* ... */
}
Initialise all resistors with __f81604_set_termination() in probe()
before registering any network device. Use f81604_set_termination()
which has the lock assert elsewhere.
Also, looking at your probe() function, in label clean_candev:, if the
second can channel fails its initialization, you do not clean the
first can channel. I suggest adding a f81604_init_netdev() and
handling the netdev issue and cleanup in that function.