Skip to content

Commit 0f28ada

Browse files
mad-jsanjuangregkh
authored andcommitted
mcb: remove is_added flag from mcb_device struct
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: 18d2881 ("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>
1 parent fc5bf78 commit 0f28ada

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

drivers/mcb/mcb-core.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,13 @@ EXPORT_SYMBOL_NS_GPL(mcb_free_dev, MCB);
387387

388388
static int __mcb_bus_add_devices(struct device *dev, void *data)
389389
{
390-
struct mcb_device *mdev = to_mcb_device(dev);
391390
int retval;
392391

393-
if (mdev->is_added)
394-
return 0;
395-
396392
retval = device_attach(dev);
397-
if (retval < 0)
393+
if (retval < 0) {
398394
dev_err(dev, "Error adding device (%d)\n", retval);
399-
400-
mdev->is_added = true;
395+
return retval;
396+
}
401397

402398
return 0;
403399
}

drivers/mcb/mcb-parse.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
9999
mdev->mem.end = mdev->mem.start + size - 1;
100100
mdev->mem.flags = IORESOURCE_MEM;
101101

102-
mdev->is_added = false;
103-
104102
ret = mcb_device_register(bus, mdev);
105103
if (ret < 0)
106104
goto err;

include/linux/mcb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ static inline struct mcb_bus *to_mcb_bus(struct device *dev)
6363
struct mcb_device {
6464
struct device dev;
6565
struct mcb_bus *bus;
66-
bool is_added;
6766
struct mcb_driver *driver;
6867
u16 id;
6968
int inst;

0 commit comments

Comments
 (0)