|
From: kosmirror <kos...@us...> - 2025-09-16 18:58:19
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "A pseudo Operating System for the Dreamcast.".
The branch, master has been updated
via 3348accdbc8a4869ef6eeaf7799067d84af64466 (commit)
from 0e0205c10c910340bb9c31cced19ba4cb24fb51a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3348accdbc8a4869ef6eeaf7799067d84af64466
Author: Paul Cercueil <pa...@cr...>
Date: Mon Sep 15 19:11:08 2025 +0200
maple: Fix race between driver attach and vblank irq
The device at unit 0 is probed using a shared frame dedicated to device
detection; devices at unit > 0 are probed using the frame of the unit 0.
This means that as soon as a unit 0 device is registered, its frame can
be used to auto-detect itself (if previously unplugged) or its children.
Therefore, prior to registering a unit 0 device into the device table,
we must ensure that all fields have been properly initialized, or we
will race with the vblank interrupt handler.
Signed-off-by: Paul Cercueil <pa...@cr...>
-----------------------------------------------------------------------
Summary of changes:
kernel/arch/dreamcast/hardware/maple/maple_driver.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/kernel/arch/dreamcast/hardware/maple/maple_driver.c b/kernel/arch/dreamcast/hardware/maple/maple_driver.c
index 00b9ba0b..f84468d6 100644
--- a/kernel/arch/dreamcast/hardware/maple/maple_driver.c
+++ b/kernel/arch/dreamcast/hardware/maple/maple_driver.c
@@ -73,6 +73,7 @@ int maple_driver_attach(maple_frame_t *det) {
maple_devinfo_t *devinfo;
maple_device_t *dev = maple_state.ports[det->dst_port].units[det->dst_unit];
bool attached = false;
+ bool dev_allocated = false;
/* Resolve some pointers first */
resp = (maple_response_t *)det->recv_buf;
@@ -89,12 +90,11 @@ int maple_driver_attach(maple_frame_t *det) {
if(!dev)
return 1;
- maple_state.ports[det->dst_port].units[det->dst_unit] = dev;
-
/* Add the basics for the initial version of the struct */
dev->port = det->dst_port;
dev->unit = det->dst_unit;
dev->frame.state = MAPLE_FRAME_VACANT;
+ dev_allocated = true;
}
memcpy(&dev->info, devinfo, sizeof(maple_devinfo_t));
@@ -102,10 +102,16 @@ int maple_driver_attach(maple_frame_t *det) {
/* Now lets allocate a new status buffer */
if(i->status_size && !dev->status) {
dev->status = calloc(1, i->status_size);
- if(!dev->status)
+ if(!dev->status) {
+ if(dev_allocated)
+ free(dev);
return 1;
+ }
}
+ if(dev_allocated)
+ maple_state.ports[det->dst_port].units[det->dst_unit] = dev;
+
if(!i->status_size || dev->status) {
/* Try to attach if we need to then break out. */
if(!(i->attach) || (i->attach(i, dev) >= 0)) {
hooks/post-receive
--
A pseudo Operating System for the Dreamcast.
|