From: Jean Delvare Date: Mon, 23 Feb 2026 16:11:41 +0000 (+0100) Subject: platform-intel: Deal with hot-unplugged devices X-Git-Tag: mdadm-4.6~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=adfa3968c62c2537600fba066e7981eaebf69ef4;p=thirdparty%2Fmdadm.git platform-intel: Deal with hot-unplugged devices 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 Co-developed-by: Jochen De Smet Signed-off-by: Jean Delvare Reviewed-by: Martin Wilck --- diff --git a/platform-intel.c b/platform-intel.c index 270aef36..963edcc4 100644 --- a/platform-intel.c +++ b/platform-intel.c @@ -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;