* [PATCH v1] i3c/master/mipi-i3c-hci: Fix a kernel panic for accessing DAT_data.
@ 2023-10-23 8:02 Billy Tsai
2023-11-03 23:41 ` Alexandre Belloni
0 siblings, 1 reply; 2+ messages in thread
From: Billy Tsai @ 2023-10-23 8:02 UTC (permalink / raw)
To: alexandre.belloni, billy_tsai, linux-i3c, linux-kernel; +Cc: BMC-SW
The `i3c_master_bus_init` function may attach the I2C devices before the
I3C bus initialization. In this flow, the DAT `alloc_entry`` will be used
before the DAT `init`. Additionally, if the `i3c_master_bus_init` fails,
the DAT `cleanup` will execute before the device is detached, which will
execue DAT `free_entry` function. The above scenario can cause the driver
to use DAT_data when it is NULL.
Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
---
drivers/i3c/master/mipi-i3c-hci/dat_v1.c | 29 ++++++++++++++++--------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
index 97bb49ff5b53..47b9b4d4ed3f 100644
--- a/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
+++ b/drivers/i3c/master/mipi-i3c-hci/dat_v1.c
@@ -64,15 +64,17 @@ static int hci_dat_v1_init(struct i3c_hci *hci)
return -EOPNOTSUPP;
}
- /* use a bitmap for faster free slot search */
- hci->DAT_data = bitmap_zalloc(hci->DAT_entries, GFP_KERNEL);
- if (!hci->DAT_data)
- return -ENOMEM;
-
- /* clear them */
- for (dat_idx = 0; dat_idx < hci->DAT_entries; dat_idx++) {
- dat_w0_write(dat_idx, 0);
- dat_w1_write(dat_idx, 0);
+ if (!hci->DAT_data) {
+ /* use a bitmap for faster free slot search */
+ hci->DAT_data = bitmap_zalloc(hci->DAT_entries, GFP_KERNEL);
+ if (!hci->DAT_data)
+ return -ENOMEM;
+
+ /* clear them */
+ for (dat_idx = 0; dat_idx < hci->DAT_entries; dat_idx++) {
+ dat_w0_write(dat_idx, 0);
+ dat_w1_write(dat_idx, 0);
+ }
}
return 0;
@@ -87,7 +89,13 @@ static void hci_dat_v1_cleanup(struct i3c_hci *hci)
static int hci_dat_v1_alloc_entry(struct i3c_hci *hci)
{
unsigned int dat_idx;
+ int ret;
+ if (!hci->DAT_data) {
+ ret = hci_dat_v1_init(hci);
+ if (ret)
+ return ret;
+ }
dat_idx = find_first_zero_bit(hci->DAT_data, hci->DAT_entries);
if (dat_idx >= hci->DAT_entries)
return -ENOENT;
@@ -103,7 +111,8 @@ static void hci_dat_v1_free_entry(struct i3c_hci *hci, unsigned int dat_idx)
{
dat_w0_write(dat_idx, 0);
dat_w1_write(dat_idx, 0);
- __clear_bit(dat_idx, hci->DAT_data);
+ if (hci->DAT_data)
+ __clear_bit(dat_idx, hci->DAT_data);
}
static void hci_dat_v1_set_dynamic_addr(struct i3c_hci *hci,
--
2.25.1
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v1] i3c/master/mipi-i3c-hci: Fix a kernel panic for accessing DAT_data.
2023-10-23 8:02 [PATCH v1] i3c/master/mipi-i3c-hci: Fix a kernel panic for accessing DAT_data Billy Tsai
@ 2023-11-03 23:41 ` Alexandre Belloni
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2023-11-03 23:41 UTC (permalink / raw)
To: linux-i3c, linux-kernel, Billy Tsai; +Cc: BMC-SW
On Mon, 23 Oct 2023 16:02:37 +0800, Billy Tsai wrote:
> The `i3c_master_bus_init` function may attach the I2C devices before the
> I3C bus initialization. In this flow, the DAT `alloc_entry`` will be used
> before the DAT `init`. Additionally, if the `i3c_master_bus_init` fails,
> the DAT `cleanup` will execute before the device is detached, which will
> execue DAT `free_entry` function. The above scenario can cause the driver
> to use DAT_data when it is NULL.
>
> [...]
Applied, thanks!
[1/1] i3c/master/mipi-i3c-hci: Fix a kernel panic for accessing DAT_data.
commit: b53e9758a31c683fc8615df930262192ed5f034b
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-03 23:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-23 8:02 [PATCH v1] i3c/master/mipi-i3c-hci: Fix a kernel panic for accessing DAT_data Billy Tsai
2023-11-03 23:41 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox