Re: [PATCH] cli()/sti() fix for drivers/net/depca.c

Denis Vlasenko (vda@port.imtp.ilyichevsk.odessa.ua)
Thu, 3 Oct 2002 10:37:03 -0200


On 2 October 2002 20:12, Francois Romieu wrote:
> Denis Vlasenko <vda@port.imtp.ilyichevsk.odessa.ua> :
> [...]
>
> > Ho to do it properly? Make a copy on stack under lock, release
> > lock, proceed with copy_to_user? That's 88 bytes at least...
>
> Please see ETHTOOL_GSTATS usage in drivers/net/8139cp.c.

This:
tmp_stats = kmalloc(sz, GFP_KERNEL);
if (!tmp_stats) return -ENOMEM;
memset(tmp_stats, 0, sz);

i = 0;
tmp_stats[i++] = le64_to_cpu(cp->nic_stats->tx_ok);
tmp_stats[i++] = le64_to_cpu(cp->nic_stats->rx_ok);
...
tmp_stats[i++] = le16_to_cpu(cp->nic_stats->tx_underrun);
tmp_stats[i++] = cp->cp_stats.rx_frags;
if (i != CP_NUM_STATS) BUG();

i = copy_to_user(useraddr + sizeof(estats), tmp_stats, sz);
kfree(tmp_stats);

kmalloc() isn't very fast, but I suppose ioctl is not that critical.

> > > - on SMP, pktStat can be updated while the copy progresses, see
> > > depca_rx().
> >
> > Should I place these pktStat updates under lp->lock?
>
> You may.
>
> depca_rx() looks strange:
> buf = skb_put(skb, len);
> [...]
> netif_rx(skb);
> [...]
> if (buf[0] & ...)

I'd say this network stuff is a bit cryptic for untrained eye :-)
What's strange with that code?

BTW, is there some (downloadable) book on Linux networking
internals?

--
vda
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/