summaryrefslogtreecommitdiffstats
path: root/drivers/staging/usbip/userspace/src/usbip_unbind.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:26:34 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:26:34 -0700
commit138051659902da7e6a09d379fee5dade2a80fcfd (patch)
treee0a90e27451b1fcd812675092d30c1059369cb87 /drivers/staging/usbip/userspace/src/usbip_unbind.c
parentd5ef642355bdd9b383ff5c18cbc6102a06eecbaf (diff)
parente1703b329f7c7ea82ea181dc4c50020f25061a2c (diff)
downloadop-kernel-dev-138051659902da7e6a09d379fee5dade2a80fcfd.zip
op-kernel-dev-138051659902da7e6a09d379fee5dade2a80fcfd.tar.gz
Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
* 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6: (741 commits) staging:iio:meter:ade7753 should be 16 bit read not 8 bit for mode register. staging:iio:kfifo_buf fix double initialization of the ring device structure. staging:iio:accel:lis3l02dq: fix incorrect pointer passed to spi_set_drvdata. staging:iio:imu fix missing register table index for some channels spectra: enable device before poking it staging: rts_pstor: Fix a miswriting staging/lirc_bt829: Return -ENODEV when no hardware is found. staging/lirc_parallel: remove pointless prototypes. staging/lirc_parallel: fix panic on rmmod staging:iio:adc:ad7476: Incorrect pointer into spi_set_drvdata. Staging: zram: Fix kunmapping order Revert "gma500: Fix dependencies" gma500: Add medfield header gma500: wire up the mrst i2c bus from chip_info gma500: Fix DPU build gma500: Clean up the DPU config and make it runtime gma500: resync with Medfield progress gma500: Use the mrst helpers and power control for mode commit gma500@ Fix backlight range error gma500: More Moorestown muddle meddling means MM maybe might modeset ... Fix up fairly trivial conflicts all over, mostly due to header file cleanup conflicts, but some deleted files and some just context changes: - Documentation/feature-removal-schedule.txt - drivers/staging/bcm/headers.h - drivers/staging/brcm80211/brcmfmac/dhd_linux.c - drivers/staging/brcm80211/brcmfmac/dhd_sdio.c - drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h - drivers/staging/brcm80211/brcmfmac/wl_iw.c - drivers/staging/et131x/et131x_netdev.c - drivers/staging/rtl8187se/ieee80211/ieee80211_softmac.c - drivers/staging/rtl8192e/r8192E.h - drivers/staging/usbip/userspace/src/utils.h
Diffstat (limited to 'drivers/staging/usbip/userspace/src/usbip_unbind.c')
-rw-r--r--drivers/staging/usbip/userspace/src/usbip_unbind.c186
1 files changed, 186 insertions, 0 deletions
diff --git a/drivers/staging/usbip/userspace/src/usbip_unbind.c b/drivers/staging/usbip/userspace/src/usbip_unbind.c
new file mode 100644
index 0000000..d5a9ab6
--- /dev/null
+++ b/drivers/staging/usbip/userspace/src/usbip_unbind.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
+ * 2005-2007 Takahiro Hirofuchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sysfs/libsysfs.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <getopt.h>
+
+#include "usbip_common.h"
+#include "utils.h"
+#include "usbip.h"
+
+static const char usbip_unbind_usage_string[] =
+ "usbip unbind <args>\n"
+ " -b, --busid=<busid> Unbind " USBIP_HOST_DRV_NAME ".ko from "
+ "device on <busid>\n";
+
+void usbip_unbind_usage(void)
+{
+ printf("usage: %s", usbip_unbind_usage_string);
+}
+
+static int unbind_device(char *busid)
+{
+ char bus_type[] = "usb";
+ struct sysfs_driver *usbip_host_drv;
+ struct sysfs_device *dev;
+ struct dlist *devlist;
+ int verified = 0;
+ int rc, ret = -1;
+
+ char attr_name[] = "bConfigurationValue";
+ char sysfs_mntpath[SYSFS_PATH_MAX];
+ char busid_attr_path[SYSFS_PATH_MAX];
+ struct sysfs_attribute *busid_attr;
+ char *val = NULL;
+ int len;
+
+ /* verify the busid device is using usbip-host */
+ usbip_host_drv = sysfs_open_driver(bus_type, USBIP_HOST_DRV_NAME);
+ if (!usbip_host_drv) {
+ err("could not open %s driver: %s", USBIP_HOST_DRV_NAME,
+ strerror(errno));
+ return -1;
+ }
+
+ devlist = sysfs_get_driver_devices(usbip_host_drv);
+ if (!devlist) {
+ err("%s is not in use by any devices", USBIP_HOST_DRV_NAME);
+ goto err_close_usbip_host_drv;
+ }
+
+ dlist_for_each_data(devlist, dev, struct sysfs_device) {
+ if (!strncmp(busid, dev->name, strlen(busid)) &&
+ !strncmp(dev->driver_name, USBIP_HOST_DRV_NAME,
+ strlen(USBIP_HOST_DRV_NAME))) {
+ verified = 1;
+ break;
+ }
+ }
+
+ if (!verified) {
+ err("device on busid %s is not using %s", busid,
+ USBIP_HOST_DRV_NAME);
+ goto err_close_usbip_host_drv;
+ }
+
+ /*
+ * NOTE: A read and write of an attribute value of the device busid
+ * refers to must be done to start probing. That way a rebind of the
+ * default driver for the device occurs.
+ *
+ * This seems very hackish and adds a lot of pointless code. I think it
+ * should be done in the kernel by the driver after del_match_busid is
+ * finished!
+ */
+
+ rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
+ if (rc < 0) {
+ err("sysfs must be mounted: %s", strerror(errno));
+ return -1;
+ }
+
+ snprintf(busid_attr_path, sizeof(busid_attr_path), "%s/%s/%s/%s/%s/%s",
+ sysfs_mntpath, SYSFS_BUS_NAME, bus_type, SYSFS_DEVICES_NAME,
+ busid, attr_name);
+
+ /* read a device attribute */
+ busid_attr = sysfs_open_attribute(busid_attr_path);
+ if (!busid_attr) {
+ err("could not open %s/%s: %s", busid, attr_name,
+ strerror(errno));
+ return -1;
+ }
+
+ if (sysfs_read_attribute(busid_attr) < 0) {
+ err("problem reading attribute: %s", strerror(errno));
+ goto err_out;
+ }
+
+ len = busid_attr->len;
+ val = malloc(len);
+ *val = *busid_attr->value;
+ sysfs_close_attribute(busid_attr);
+
+ /* notify driver of unbind */
+ rc = modify_match_busid(busid, 0);
+ if (rc < 0) {
+ err("unable to unbind device on %s", busid);
+ goto err_out;
+ }
+
+ /* write the device attribute */
+ busid_attr = sysfs_open_attribute(busid_attr_path);
+ if (!busid_attr) {
+ err("could not open %s/%s: %s", busid, attr_name,
+ strerror(errno));
+ return -1;
+ }
+
+ rc = sysfs_write_attribute(busid_attr, val, len);
+ if (rc < 0) {
+ err("problem writing attribute: %s", strerror(errno));
+ goto err_out;
+ }
+ sysfs_close_attribute(busid_attr);
+
+ ret = 0;
+ printf("unbind device on busid %s: complete\n", busid);
+
+err_out:
+ free(val);
+err_close_usbip_host_drv:
+ sysfs_close_driver(usbip_host_drv);
+
+ return ret;
+}
+
+int usbip_unbind(int argc, char *argv[])
+{
+ static const struct option opts[] = {
+ { "busid", required_argument, NULL, 'b' },
+ { NULL, 0, NULL, 0 }
+ };
+
+ int opt;
+ int ret = -1;
+
+ for (;;) {
+ opt = getopt_long(argc, argv, "b:", opts, NULL);
+
+ if (opt == -1)
+ break;
+
+ switch (opt) {
+ case 'b':
+ ret = unbind_device(optarg);
+ goto out;
+ default:
+ goto err_out;
+ }
+ }
+
+err_out:
+ usbip_unbind_usage();
+out:
+ return ret;
+}
OpenPOWER on IntegriCloud