Re: [PATCH net] mctp i2c: fix double free of midev on netdev register failure

From: Kenny Hsieh

Date: Thu Oct 22 2026 - 03:22:33 EST


Hi Matt,

On Thu, 2026-10-22 at 12:39 +0800, Matt Johnston wrote:
> I wonder if it would be better to delete mctp_i2c_ndo_uninit() and move the
> the mctp_i2c_midev_free() to mctp_i2c_unregister(), before free_netdev().
> Then the free sequence would be symmetrical with the init sequence in
> mctp_i2c_add_netdev.

Agreed, that is cleaner than making the free idempotent. Here's what I'm
planning, let me know if it looks right and I'll go ahead:

- in mctp_i2c_unregister(), deselect mcli->sel if it points at this
midev, before mctp_unregister_netdev(), so its dev_hold() doesn't
block the unregister.
- call mctp_i2c_midev_free() after mctp_unregister_netdev() and before
free_netdev(), and take the sel handling out of it since that now
happens earlier.
- leave the mctp_i2c_add_netdev() error path calling
mctp_i2c_midev_free() as it is, which then becomes the only free on
a failed register.
- delete mctp_i2c_ndo_uninit() and .ndo_uninit.