Hi, On Wed, Feb 16, 2022 at 02:29:34PM +0100, Tobias Waldekranz wrote: > +static int mv88e6xxx_sid_new(struct mv88e6xxx_chip *chip, u8 *sid) > +{ > + DECLARE_BITMAP(busy, MV88E6XXX_N_SID) = { 0 }; > + struct mv88e6xxx_mst *mst; > + > + set_bit(0, busy); > + > + list_for_each_entry(mst, &chip->msts, node) { > + set_bit(mst->stu.sid, busy); > + } Do you need these set_bit() operations to be atomic? Would __set_bit() produce better code? > + > + *sid = find_first_zero_bit(busy, MV88E6XXX_N_SID); > + > + return (*sid >= mv88e6xxx_max_sid(chip)) ? -ENOSPC : 0; Hmm. Let's hope that mv88e6xxx_max_sid() never returns a value larger than MV88E6XXX_N_SID. > +} > + ... > +static int mv88e6xxx_sid_get(struct mv88e6xxx_chip *chip, struct net_device *br, > + u16 mstid, u8 *sid) > +{ > + struct mv88e6xxx_mst *mst; > + int err; > + > + if (!br) > + return 0; > + > + if (!mv88e6xxx_has_stu(chip)) > + return -EOPNOTSUPP; > + > + list_for_each_entry(mst, &chip->msts, node) { > + if (mst->br == br && mst->mstid == mstid) { > + refcount_inc(&mst->refcnt); > + *sid = mst->stu.sid; > + return 0; > + } > + } > + > + err = mv88e6xxx_sid_new(chip, sid); > + if (err) > + return err; > + > + mst = kzalloc(sizeof(*mst), GFP_KERNEL); > + if (!mst) > + return -ENOMEM; > + > + INIT_LIST_HEAD(&mst->node); There is no need to initialise the node if you're then going to be adding it to the list. > + refcount_set(&mst->refcnt, 1); > + mst->br = br; > + mst->mstid = mstid; > + mst->stu.valid = true; > + mst->stu.sid = *sid; > + list_add_tail(&mst->node, &chip->msts); > + return mv88e6xxx_stu_loadpurge(chip, &mst->stu); I haven't checked what the locking is here - I hope it's not possible for two of these to run concurrently. Thanks. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!