[ndctl] ndctl/lib: Fix duplicate bus detection
diff mbox series

Message ID 156520029994.1268132.13388510714364773911.stgit@dwillia2-desk3.amr.corp.intel.com
State Accepted
Commit d961a474be65c8195bb069c470b01f951bd2eb90
Headers show
Series
  • [ndctl] ndctl/lib: Fix duplicate bus detection
Related show

Commit Message

Dan Williams Aug. 7, 2019, 5:51 p.m. UTC
After an ndctl_invalidate() event the next add_bus() invocation attempts
to rescan for new bus objects and drop duplicate instances that match
existing bus objects. However, the implementation mistakenly expects
that ndctl_bus_get_provider_name() returns a unique identifier per-bus,
but it is perfectly acceptable for unique buses to share a 'provider
name'. Use the bus device-name to disambiguate buses with the same
'provider name'.

Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/lib/libndctl.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 4d9cc7e29c6b..6596f94edef8 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -889,7 +889,9 @@  static void *add_bus(void *parent, int id, const char *ctl_base)
 
 	ndctl_bus_foreach(ctx, bus_dup)
 		if (strcmp(ndctl_bus_get_provider(bus_dup),
-					ndctl_bus_get_provider(bus)) == 0) {
+					ndctl_bus_get_provider(bus)) == 0
+				&& strcmp(ndctl_bus_get_devname(bus_dup),
+					ndctl_bus_get_devname(bus)) == 0) {
 			free_bus(bus, NULL);
 			free(path);
 			return bus_dup;