Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 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>

authored by

Jorge Sanjuan Garcia and committed by
Greg Kroah-Hartman
0f28ada1 fc5bf78b

+3 -10
+3 -7
drivers/mcb/mcb-core.c
··· 387 387 388 388 static int __mcb_bus_add_devices(struct device *dev, void *data) 389 389 { 390 - struct mcb_device *mdev = to_mcb_device(dev); 391 390 int retval; 392 391 393 - if (mdev->is_added) 394 - return 0; 395 - 396 392 retval = device_attach(dev); 397 - if (retval < 0) 393 + if (retval < 0) { 398 394 dev_err(dev, "Error adding device (%d)\n", retval); 399 - 400 - mdev->is_added = true; 395 + return retval; 396 + } 401 397 402 398 return 0; 403 399 }
-2
drivers/mcb/mcb-parse.c
··· 99 99 mdev->mem.end = mdev->mem.start + size - 1; 100 100 mdev->mem.flags = IORESOURCE_MEM; 101 101 102 - mdev->is_added = false; 103 - 104 102 ret = mcb_device_register(bus, mdev); 105 103 if (ret < 0) 106 104 goto err;
-1
include/linux/mcb.h
··· 63 63 struct mcb_device { 64 64 struct device dev; 65 65 struct mcb_bus *bus; 66 - bool is_added; 67 66 struct mcb_driver *driver; 68 67 u16 id; 69 68 int inst;