Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F154467746
D48850.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D48850.diff
View Options
diff --git a/sys/dev/rtsx/rtsx.c b/sys/dev/rtsx/rtsx.c
--- a/sys/dev/rtsx/rtsx.c
+++ b/sys/dev/rtsx/rtsx.c
@@ -686,40 +686,46 @@
rtsx_card_task(void *arg, int pending __unused)
{
struct rtsx_softc *sc = arg;
+ device_t child;
+ bool present;
- if (rtsx_is_card_present(sc)) {
- sc->rtsx_flags |= RTSX_F_CARD_PRESENT;
+ RTSX_LOCK(sc);
+ child = sc->rtsx_mmc_dev;
+ present = rtsx_is_card_present(sc);
+ RTSX_UNLOCK(sc);
+
+ if (present && child == NULL) {
/* Card is present, attach if necessary. */
- if (sc->rtsx_mmc_dev == NULL) {
- if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
- device_printf(sc->rtsx_dev, "Card inserted\n");
+ if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
+ device_printf(sc->rtsx_dev, "Card inserted\n");
- sc->rtsx_read_count = sc->rtsx_write_count = 0;
- RTSX_LOCK(sc);
- sc->rtsx_mmc_dev = device_add_child(sc->rtsx_dev, "mmc", DEVICE_UNIT_ANY);
- RTSX_UNLOCK(sc);
- if (sc->rtsx_mmc_dev == NULL) {
- device_printf(sc->rtsx_dev, "Adding MMC bus failed\n");
- } else {
- device_set_ivars(sc->rtsx_mmc_dev, sc);
- device_probe_and_attach(sc->rtsx_mmc_dev);
- }
+ sc->rtsx_read_count = sc->rtsx_write_count = 0;
+ child = device_add_child(sc->rtsx_dev, "mmc", DEVICE_UNIT_ANY);
+ if (child == NULL) {
+ device_printf(sc->rtsx_dev, "Adding MMC bus failed\n");
+ } else {
+ device_set_ivars(child, sc);
+ device_probe_and_attach(child);
}
- } else {
+
+ RTSX_LOCK(sc);
+ sc->rtsx_mmc_dev = child;
+ sc->rtsx_flags |= RTSX_F_CARD_PRESENT;
+ RTSX_UNLOCK(sc);
+ } else if (!present && child != NULL) {
+ if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
+ device_printf(sc->rtsx_dev, "Card removed\n");
+ if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
+ device_printf(sc->rtsx_dev, "Read count: %jx, write count: %jx\n",
+ (uintmax_t)sc->rtsx_read_count, (uintmax_t)sc->rtsx_write_count);
+
+ RTSX_LOCK(sc);
sc->rtsx_flags &= ~RTSX_F_CARD_PRESENT;
- /* Card isn't present, detach if necessary. */
- if (sc->rtsx_mmc_dev != NULL) {
- if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
- device_printf(sc->rtsx_dev, "Card removed\n");
+ sc->rtsx_mmc_dev = NULL;
+ RTSX_UNLOCK(sc);
- if (sc->rtsx_debug_mask & RTSX_DEBUG_BASIC)
- device_printf(sc->rtsx_dev, "Read count: %jx, write count: %jx\n",
- (uintmax_t)sc->rtsx_read_count,
- (uintmax_t)sc->rtsx_write_count);
- if (device_delete_child(sc->rtsx_dev, sc->rtsx_mmc_dev))
- device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n");
- sc->rtsx_mmc_dev = NULL;
- }
+ if (device_delete_child(sc->rtsx_dev, child))
+ device_printf(sc->rtsx_dev, "Detaching MMC bus failed\n");
}
}
#endif /* MMCCAM */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Apr 29, 4:51 PM (5 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
32353810
Default Alt Text
D48850.diff (2 KB)
Attached To
Mode
D48850: rtsx: refine locking in rtsx_card_task()
Attached
Detach File
Event Timeline
Log In to Comment