> +/* DSA can directly translate this to a normal MDB add, but on the CPU port.
> + * But because multiple user ports can join the same multicast group and the
> + * bridge will emit a notification for each port, we need to add/delete the
> + * entry towards the host only once, so we reference count it.
> + */
> +static int dsa_host_mdb_add(struct dsa_port *dp,
> +                         const struct switchdev_obj_port_mdb *mdb,
> +                         struct switchdev_trans *trans)
> +{
> +     struct dsa_port *cpu_dp = dp->cpu_dp;
> +     struct dsa_switch *ds = dp->ds;
> +     struct dsa_host_addr *a;
> +     int err;
> +
> +     a = dsa_host_addr_find(&ds->host_mdb, mdb);
> +     if (a) {
> +             /* Only the commit phase is refcounted */
> +             if (switchdev_trans_ph_commit(trans))
> +                     refcount_inc(&a->refcount);
> +             return 0;
> +     }
> +
> +     err = dsa_port_mdb_add(cpu_dp, mdb, trans);
> +     if (err)
> +             return err;
> +
> +     /* Only the commit phase is refcounted, so don't save this just yet */
> +     if (switchdev_trans_ph_prepare(trans))
> +             return 0;
> +
> +     a = kzalloc(sizeof(*a), GFP_KERNEL);
> +     if (!a)
> +             return -ENOMEM;

Hi Vladimir

This allocation should be done in the prepare phase, since it can
fail. You should only return catastrophic errors during the commit
phase.

So i think you can allocate it in the prepare phase, but leave the
reference count as 0. Then increment it in the commit phase.

And then make the dsa_host_mdb_del() decrement the specific refcount,
and then do a generic garbage collect for all entries with refcount of
0, to cleanup any left over failures.

   Andrew

Reply via email to