]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
platform-intel: Deal with hot-unplugged devices
authorJean Delvare <jdelvare@suse.de>
Mon, 23 Feb 2026 16:11:41 +0000 (17:11 +0100)
committerMariusz Tkaczyk <mtkaczyk@kernel.org>
Fri, 6 Mar 2026 12:46:43 +0000 (13:46 +0100)
Don't assume that realpath() will always succeed, if a device gets
hot-unplugged then realpath() can fail. Handle the situation
gracefully, and report an error only if the failure is for a
different reason.

Reported-by: Jochen De Smet <jochen.desmet@dell.com>
Co-developed-by: Jochen De Smet <jochen.desmet@dell.com>
Signed-off-by: Jean Delvare <jdelvare@suse.de>
Reviewed-by: Martin Wilck <mwilck@suse.com>
platform-intel.c

index 270aef36ae9a37be43fc266bc56b4f9859c9bcd6..963edcc4926826b4eb2c191d2d3e6168053061e8 100644 (file)
@@ -233,6 +233,13 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
                if (type == SYS_DEV_NVME) {
                        struct sys_dev *dev;
                        char *rp = realpath(path, NULL);
+                       if (!rp) {
+                               /* Device may have been hot-unplugged */
+                               if (errno != ENOENT)
+                                       pr_err("Unable to get real path for '%s', err = %d\n",
+                                              path, errno);
+                               continue;
+                       }
                        for (dev = vmd; dev; dev = dev->next) {
                                if ((strncmp(dev->path, rp, strlen(dev->path)) == 0))
                                        skip = 1;
@@ -244,6 +251,13 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
                if (type == SYS_DEV_SATA) {
                        struct sys_dev *dev;
                        char *rp = realpath(path, NULL);
+                       if (!rp) {
+                               /* Device may have been hot-unplugged */
+                               if (errno != ENOENT)
+                                       pr_err("Unable to get real path for '%s', err = %d\n",
+                                              path, errno);
+                               continue;
+                       }
                        for (dev = vmd; dev; dev = dev->next) {
                                if ((strncmp(dev->path, rp, strlen(dev->path)) == 0))
                                        type = SYS_DEV_SATA_VMD;