From: Logan Gunthorpe Date: Tue, 28 Mar 2017 19:26:41 +0000 (-0600) Subject: fabrics: Fix disconnect_by_device from disconnecting instance 0 on error X-Git-Tag: v1.3~16^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=41e3e96c12a138eddfe41f1db4deb57044bd4307;p=users%2Fsagi%2Fnvme-cli.git fabrics: Fix disconnect_by_device from disconnecting instance 0 on error I was a bit surprised that running: nvme disconnect -d /dev/nvme1 actually disconnected nvme0 and I could never disconnect nvme1. Turns out the code was not expecting a full path and silently used instance zero if it failed to parse any arguments. This patch fixes it so that it ignores any path component and fails if sscanf doesn't match any items. --- diff --git a/fabrics.c b/fabrics.c index d93cfe7a..cd671c7a 100644 --- a/fabrics.c +++ b/fabrics.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "parser.h" #include "nvme-ioctl.h" @@ -899,9 +900,12 @@ static int disconnect_by_device(char *device) int instance; int ret; + device = basename(device); ret = sscanf(device, "nvme%d", &instance); if (ret < 0) return ret; + if (!ret) + return -1; return remove_ctrl(instance); }