summaryrefslogtreecommitdiffstats
path: root/drivers/mcb/mcb-core.c
Commit message (Collapse)AuthorAgeFilesLines
* mcb: fix error handling for different scenarios when parsingSanjuán García, Jorge2023-11-281-0/+1
| | | | | | | | | | | | | | | | | | commit 63ba2d07b4be72b94216d20561f43e1150b25d98 upstream. chameleon_parse_gdd() may fail for different reasons and end up in the err tag. Make sure we at least always free the mcb_device allocated with mcb_alloc_dev(). If mcb_device_register() fails, make sure to give up the reference in the same place the device was added. Fixes: 728ac3389296 ("mcb: mcb-parse: fix error handing in chameleon_parse_gdd()") Cc: stable <stable@kernel.org> Reviewed-by: Jose Javier Rodriguez Barbarin <JoseJavier.Rodriguez@duagon.com> Signed-off-by: Jorge Sanjuan Garcia <jorge.sanjuangarcia@duagon.com> Link: https://lore.kernel.org/r/20231019141434.57971-2-jorge.sanjuangarcia@duagon.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: remove is_added flag from mcb_device structJorge Sanjuan Garcia2023-10-051-7/+3
| | | | | | | | | | | | | | | | | | | | | | | 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>
* driver core: make struct bus_type.uevent() take a const *Greg Kroah-Hartman2023-01-271-2/+2
| | | | | | | | | | | | The uevent() callback in struct bus_type should not be modifying the device that is passed into it, so mark it as a const * and propagate the function signature changes out into all relevant subsystems that use this callback. Acked-by: Rafael J. Wysocki <rafael@kernel.org> Acked-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20230111113018.459199-16-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* drivers: mcb: fix resource leak in mcb_probe()Zhengchao Shao2022-12-021-1/+3
| | | | | | | | | | | When probe hook function failed in mcb_probe(), it doesn't put the device. Compiled test only. Fixes: 7bc364097a89 ("mcb: Acquire reference to device in probe") Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com> Signed-off-by: Johannes Thumshirn <jth@kernel.org> Link: https://lore.kernel.org/r/9f87de36bfb85158b506cb78c6fc9db3f6a3bad1.1669624063.git.johannes.thumshirn@wdc.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* drivers: mcb: directly use ida_alloc()/free()keliu2022-07-121-2/+2
| | | | | | | | | | Use ida_alloc()/ida_free() instead of deprecated ida_simple_get()/ida_simple_remove() . Signed-off-by: keliu <liuke94@huawei.com> Signed-off-by: Johannes Thumshirn <jth@kernel.org> Link: https://lore.kernel.org/r/480676bee970da16bf1fa8565277240014395ba3.1657607743.git.johannes.thumshirn@wdc.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: fix error handling in mcb_alloc_bus()Dan Carpenter2021-09-141-6/+6
| | | | | | | | | | | | | | | | | | There are two bugs: 1) If ida_simple_get() fails then this code calls put_device(carrier) but we haven't yet called get_device(carrier) and probably that leads to a use after free. 2) After device_initialize() then we need to use put_device() to release the bus. This will free the internal resources tied to the device and call mcb_free_bus() which will free the rest. Fixes: 5d9e2ab9fea4 ("mcb: Implement bus->dev.release callback") Fixes: 18d288198099 ("mcb: Correctly initialize the bus's device") Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Johannes Thumshirn <jth@kernel.org> Link: https://lore.kernel.org/r/32e160cf6864ce77f9d62948338e24db9fd8ead9.1630931319.git.johannes.thumshirn@wdc.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* bus: Make remove callback return voidUwe Kleine-König2021-07-211-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The driver core ignores the return value of this callback because there is only little it can do when a device disappears. This is the final bit of a long lasting cleanup quest where several buses were converted to also return void from their remove callback. Additionally some resource leaks were fixed that were caused by drivers returning an error code in the expectation that the driver won't go away. With struct bus_type::remove returning void it's prevented that newly implemented buses return an ignored error code and so don't anticipate wrong expectations for driver authors. Reviewed-by: Tom Rix <trix@redhat.com> (For fpga) Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Cornelia Huck <cohuck@redhat.com> (For drivers/s390 and drivers/vfio) Acked-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> (For ARM, Amba and related parts) Acked-by: Mark Brown <broonie@kernel.org> Acked-by: Chen-Yu Tsai <wens@csie.org> (for sunxi-rsb) Acked-by: Pali Rohár <pali@kernel.org> Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org> (for media) Acked-by: Hans de Goede <hdegoede@redhat.com> (For drivers/platform) Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-By: Vinod Koul <vkoul@kernel.org> Acked-by: Juergen Gross <jgross@suse.com> (For xen) Acked-by: Lee Jones <lee.jones@linaro.org> (For mfd) Acked-by: Johannes Thumshirn <jth@kernel.org> (For mcb) Acked-by: Johan Hovold <johan@kernel.org> Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> (For slimbus) Acked-by: Kirti Wankhede <kwankhede@nvidia.com> (For vfio) Acked-by: Maximilian Luz <luzmaximilian@gmail.com> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> (For ulpi and typec) Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> (For ipack) Acked-by: Geoff Levand <geoff@infradead.org> (For ps3) Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com> (For thunderbolt) Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> (For intel_th) Acked-by: Dominik Brodowski <linux@dominikbrodowski.net> (For pcmcia) Acked-by: Rafael J. Wysocki <rafael@kernel.org> (For ACPI) Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org> (rpmsg and apr) Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> (For intel-ish-hid) Acked-by: Dan Williams <dan.j.williams@intel.com> (For CXL, DAX, and NVDIMM) Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com> (For isa) Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (For firewire) Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> (For hid) Acked-by: Thorsten Scherer <t.scherer@eckelmann.de> (For siox) Acked-by: Sven Van Asbroeck <TheSven73@gmail.com> (For anybuss) Acked-by: Ulf Hansson <ulf.hansson@linaro.org> (For MMC) Acked-by: Wolfram Sang <wsa@kernel.org> # for I2C Acked-by: Sudeep Holla <sudeep.holla@arm.com> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Finn Thain <fthain@linux-m68k.org> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20210713193522.1770306-6-u.kleine-koenig@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* drivers: mcb: use symbol namespacesJohannes Thumshirn2019-11-031-14/+14
| | | | | | | | | | | Now that we have symbol namespaces, use them in MCB to not pollute the default namespace with MCB internals. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Jessica Yu <jeyu@kernel.org> Reviewed-by: Michael Moese <mmoese@suse.de> Link: https://lore.kernel.org/r/20191016100158.1400-1-jthumshirn@suse.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441Thomas Gleixner2019-06-051-4/+1
| | | | | | | | | | | | | | | | | | | | | Based on 1 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation version 2 of the license extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 315 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Armijn Hemel <armijn@tjaldur.nl> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190531190115.503150771@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: introduce mcb_get_resource()Johannes Thumshirn2017-08-281-1/+19
| | | | | | | | Introduce mcb_get_resource() as a common accessor to a mcb device's memory or IRQ resources. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: Add a dma_device to mcb_deviceMichael Moese2016-09-271-0/+1
| | | | | | | | | | | | When performing DMA operations on a MCB device, the device needed for using the DMA API is "mcb_device->bus_carrier". This is rather lengthy, so a shortcut is introduced to struct mcb_device in order to ensure the MCB device driver uses the correct device for DMA operations. Signed-off-by: Michael Moese <michael.moese@men.de> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: remove sub-device handling codeJohannes Thumshirn2016-08-311-17/+0
| | | | | | | | | | | | | The MEN Chameleon specification states that a chameleon FPGA can include a bridge descriptor, which then opens up a new bus behind this bridge. MCB included subdevice handling code in the core, but no support for bus descriptors in the parser, due to a lack of hardware access. As this is technically dead code, but it gets executed on a device add, I've decided to remove it. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: Acquire reference to carrier module in coreJohannes Thumshirn2016-06-131-1/+15
| | | | | | | | | | | Acquire a reference to the carrier's kernel module in bus code, so it can't be removed from the kernel while it still has a bus and thus possibly devices attached to it. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reported-by: Andreas Werner <andreas.werner@men.de> Tested-by: Andreas Werner <andreas.werner@men.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: Acquire reference to device in probeJohannes Thumshirn2016-06-131-0/+1
| | | | | | | | | | | | | mcb_probe() does not aqcuire a reference to the probed device but drops one when removing the device. As it is actually using the device, it should grab a reference via get_device(). This could lead to a panic found with a rmmod/modprobe stress test Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reported-by: Andreas Werner <andreas.werner@men.de> Tested-by: Andreas Werner <andreas.werner@men.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: Implement bus->dev.release callbackJohannes Thumshirn2016-05-031-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The mcb_bus structure previously was released in mcb_release_bus. This lead to the following warning on module unload: ------------[ cut here ]------------ WARNING: CPU: 1 PID: 2032 at drivers/base/core.c:251 device_release+0x73/0x90 Device 'mcb:0' does not have a release() function, it is broken and must be fixed. Modules linked in: men_z135_uart mcb_pci(-) mcb CPU: 1 PID: 2032 Comm: rmmod Not tainted 4.6.0-rc4+ #3 Hardware name: N/A N/A/COMe-mBTi10, BIOS MVV1R921 X64 10/14/2015 00000286 00000286 c0117de4 c12d6f16 c0117e2c c18be0d3 c0117dfc c104f6e1 000000fb f5ccbe08 f5ccbe00 f5c64600 c0117e18 c104f728 00000009 00000000 c0117e10 c18db674 c0117e2c c0117e3c c13ce5c3 c18be0d3 000000fb c18db674 Call Trace: [<c12d6f16>] dump_stack+0x47/0x61 [<c104f6e1>] __warn+0xc1/0xe0 [<c104f728>] warn_slowpath_fmt+0x28/0x30 [<c13ce5c3>] device_release+0x73/0x90 [<c12d92e4>] kobject_release+0x34/0x80 [<c12d929d>] ? kobject_del+0x2d/0x40 [<c12d9205>] kobject_put+0x25/0x50 [<c13ce77f>] put_device+0xf/0x20 [<c13d114b>] klist_devices_put+0xb/0x10 [<c1752673>] klist_next+0x73/0xf0 [<c13d1140>] ? unbind_store+0x100/0x100 [<f8a23370>] ? mcb_bus_add_devices+0x30/0x30 [mcb] [<c13d0a81>] bus_for_each_dev+0x51/0x80 [<f8a23319>] mcb_release_bus+0x19/0x40 [mcb] [<f8a23370>] ? mcb_bus_add_devices+0x30/0x30 [mcb] [<f8a2b033>] mcb_pci_remove+0x13/0x20 [mcb_pci] [<c130d358>] pci_device_remove+0x28/0xb0 [<c13d201b>] __device_release_driver+0x7b/0x110 [<c13d2847>] driver_detach+0x87/0x90 [<c13d1b9b>] bus_remove_driver+0x3b/0x80 [<c13d2ed0>] driver_unregister+0x20/0x50 [<c130be53>] pci_unregister_driver+0x13/0x60 [<f8a2b1f4>] mcb_pci_driver_exit+0xd/0xf [mcb_pci] [<c10be588>] SyS_delete_module+0x138/0x200 [<c1159208>] ? ____fput+0x8/0x10 [<c1068054>] ? task_work_run+0x74/0x90 [<c1001879>] do_fast_syscall_32+0x69/0x120 [<c1757597>] sysenter_past_esp+0x40/0x6a ---[ end trace 1ed34c2aa3019875 ]--- Release a mcb_bus' memory on the device's release callback, to avoid above warning. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reported-by: Andreas Werner <andreas.werner@men.de> Tested-by: Andreas Werner <andreas.werner@men.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: export bus information via sysfsJohannes Thumshirn2016-05-031-0/+60
| | | | | | | | | | Export information about the bus stored in the FPGA's header to userspace via sysfs, instead of hiding it in pr_debug()s from everyone. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Andreas Werner <andreas.werner@men.de> Tested-by: Andreas Werner <andreas.werner@men.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: Correctly initialize the bus's deviceJohannes Thumshirn2016-05-031-3/+16
| | | | | | | | | | The mcb bus' device member wasn't correctly initialized and thus wasn't placed correctly into the driver model. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Andreas Werner <andreas.werner@men.de> Tested-by: Andreas Werner <andreas.werner@men.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: Destroy IDA on module unloadJohannes Thumshirn2015-10-291-0/+1
| | | | | | | Destroy mcb_ida on module_unload Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* mcb: Add support for shared PCI IRQsJohannes Thumshirn2014-05-271-5/+15
| | | | | | | Add support for shared PCI IRQs to mcb and mcb-pci. Signed-off-by: Johannes Thumshirn <johannes.thumshirn@men.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* drivers: Introduce MEN Chameleon BusJohannes Thumshirn2014-02-281-0/+414
The MCB (MEN Chameleon Bus) is a Bus specific to MEN Mikroelektronik FPGA based devices. It is used to identify MCB based IP-Cores within an FPGA and provide the necessary framework for instantiating drivers for these devices. Signed-off-by: Johannes Thumshirn <johannes.thumshirn@men.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>