From d3248c4170bc457db47338018b6b6e97a4fbf8b1 Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Mon, 25 Feb 2019 17:30:01 +0000 Subject: [PATCH] Resolve a name conflict when both SpiFlash and DataFlash devices are present. Both SpiFlash (mx25l) and DataFlash (at45d) drivers create a disk device with a name of /dev/flash/spiN where N is the driver's unit number. If both types of devices are present in the same system, this creates a fatal conflict that prevents attachment of whichever device attaches second (because mx25l0 and at45d0 both try to create a spi0). This gives each type of device a unique name (mx25lN or at45dN respectively) and also adds an alias of spiN for compatibility. When both device types appear in the same system, only the first to attach gets the spiN alias. When the second device attaches there is a non-fatal warning that the alias can't be created, but both devices are still accessible via their primary names (and there is no need for the spiN name to work for backwards compatibility on such a system, because it has never been possible to use the spiN names when both devices exist). --- sys/dev/flash/at45d.c | 3 ++- sys/dev/flash/mx25l.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/dev/flash/at45d.c b/sys/dev/flash/at45d.c index 06c55853862..92923164b13 100644 --- a/sys/dev/flash/at45d.c +++ b/sys/dev/flash/at45d.c @@ -338,13 +338,14 @@ at45d_delayed_attach(void *xsc) sc->disk->d_open = at45d_open; sc->disk->d_close = at45d_close; sc->disk->d_strategy = at45d_strategy; - sc->disk->d_name = "flash/spi"; + sc->disk->d_name = "flash/at45d"; sc->disk->d_drv1 = sc; sc->disk->d_maxsize = DFLTPHYS; sc->disk->d_sectorsize = pagesize; sc->disk->d_mediasize = pagesize * ident->pagecount; sc->disk->d_unit = device_get_unit(sc->dev); disk_create(sc->disk, DISK_VERSION); + disk_add_alias(sc->sc_disk, "flash/spi"); bioq_init(&sc->bio_queue); kproc_create(&at45d_task, sc, &sc->p, 0, 0, "task: at45d flash"); sc->taskstate = TSTATE_RUNNING; diff --git a/sys/dev/flash/mx25l.c b/sys/dev/flash/mx25l.c index 6110c408263..2b98619de0e 100644 --- a/sys/dev/flash/mx25l.c +++ b/sys/dev/flash/mx25l.c @@ -510,7 +510,7 @@ mx25l_attach(device_t dev) sc->sc_disk->d_strategy = mx25l_strategy; sc->sc_disk->d_getattr = mx25l_getattr; sc->sc_disk->d_ioctl = mx25l_ioctl; - sc->sc_disk->d_name = "flash/spi"; + sc->sc_disk->d_name = "flash/mx25l"; sc->sc_disk->d_drv1 = sc; sc->sc_disk->d_maxsize = DFLTPHYS; sc->sc_disk->d_sectorsize = MX25L_SECTORSIZE; @@ -522,6 +522,7 @@ mx25l_attach(device_t dev) sizeof(sc->sc_disk->d_descr)); disk_create(sc->sc_disk, DISK_VERSION); + disk_add_alias(sc->sc_disk, "flash/spi"); bioq_init(&sc->sc_bio_queue); kproc_create(&mx25l_task, sc, &sc->sc_p, 0, 0, "task: mx25l flash");