]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mcb: remove is_added flag from mcb_device struct
authorJorge Sanjuan Garcia <jorge.sanjuangarcia@duagon.com>
Wed, 6 Sep 2023 11:49:26 +0000 (11:49 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Oct 2023 09:13:30 +0000 (11:13 +0200)
commit 0f28ada1fbf0054557cddcdb93ad17f767105208 upstream.

When calling mcb_bus_add_devices(), both mcb devices and the mcb
bus will attempt to attach a device to a driver because they share
the same bus_type. This causes an issue when trying to cast the
container of the device to mcb_device struct using to_mcb_device(),
leading to a wrong cast when the mcb_bus is added. A crash occurs
when freing the ida resources as the bus numbering of mcb_bus gets
confused with the is_added flag on the mcb_device struct.

The only reason for this cast was to keep an is_added flag on the
mcb_device struct that does not seem necessary. The function
device_attach() handles already bound devices and the mcb subsystem
does nothing special with this is_added flag so remove it completely.

Fixes: 18d288198099 ("mcb: Correctly initialize the bus's device")
Cc: stable <stable@kernel.org>
Signed-off-by: Jorge Sanjuan Garcia <jorge.sanjuangarcia@duagon.com>
Co-developed-by: Jose Javier Rodriguez Barbarin <JoseJavier.Rodriguez@duagon.com>
Signed-off-by: Jose Javier Rodriguez Barbarin <JoseJavier.Rodriguez@duagon.com>
Link: https://lore.kernel.org/r/20230906114901.63174-2-JoseJavier.Rodriguez@duagon.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mcb/mcb-core.c
drivers/mcb/mcb-parse.c
include/linux/mcb.h

index 7fd32b0183dc106e556d927ffed5d8addbfc99d0..6e7e91387f3c468a60c7fb066ffcdabd8c2d7f2c 100644 (file)
@@ -392,17 +392,13 @@ EXPORT_SYMBOL_GPL(mcb_free_dev);
 
 static int __mcb_bus_add_devices(struct device *dev, void *data)
 {
-       struct mcb_device *mdev = to_mcb_device(dev);
        int retval;
 
-       if (mdev->is_added)
-               return 0;
-
        retval = device_attach(dev);
-       if (retval < 0)
+       if (retval < 0) {
                dev_err(dev, "Error adding device (%d)\n", retval);
-
-       mdev->is_added = true;
+               return retval;
+       }
 
        return 0;
 }
index 3636349648b4f0e15cfbec120575c9428472ca3f..08a85e43ef88507dda8279b60c033d6f67892c98 100644 (file)
@@ -98,8 +98,6 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
        mdev->mem.end = mdev->mem.start + size - 1;
        mdev->mem.flags = IORESOURCE_MEM;
 
-       mdev->is_added = false;
-
        ret = mcb_device_register(bus, mdev);
        if (ret < 0)
                goto err;
index b1a0ad9d23b3070ffb3fd5a8adc07d6330e96739..8052e5f20630ae739ed7ae519564416a20d8de21 100644 (file)
@@ -66,7 +66,6 @@ static inline struct mcb_bus *to_mcb_bus(struct device *dev)
 struct mcb_device {
        struct device dev;
        struct mcb_bus *bus;
-       bool is_added;
        struct mcb_driver *driver;
        u16 id;
        int inst;