All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <shuah.kh@samsung.com>
To: Valentina Manea <valentina.manea.m@gmail.com>,
	gregkh@linuxfoundation.org
Cc: tobias.polzer@fau.de, dominik.paulus@fau.de,
	ly80toro@cip.cs.fau.de, ihadzic@research.bell-labs.com,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	devel@driverdev.osuosl.org, firefly@lists.rosedu.org,
	Shuah Khan <shuah.kh@samsung.com>
Subject: Re: [PATCH 04/12] staging: usbip: userspace: migrate usbip_list to libudev
Date: Thu, 06 Mar 2014 13:57:01 -0700	[thread overview]
Message-ID: <5318E11D.7010106@samsung.com> (raw)
In-Reply-To: <1393960252-21247-5-git-send-email-valentina.manea.m@gmail.com>

On 03/04/2014 12:10 PM, Valentina Manea wrote:
> This patch modifies usbip_list to use libudev.
>
> Signed-off-by: Valentina Manea <valentina.manea.m@gmail.com>
> ---
>   drivers/staging/usbip/userspace/src/usbip_list.c | 137 +++++++++--------------
>   1 file changed, 51 insertions(+), 86 deletions(-)
>
> diff --git a/drivers/staging/usbip/userspace/src/usbip_list.c b/drivers/staging/usbip/userspace/src/usbip_list.c
> index 8864fa2..2255107 100644
> --- a/drivers/staging/usbip/userspace/src/usbip_list.c
> +++ b/drivers/staging/usbip/userspace/src/usbip_list.c
> @@ -17,7 +17,7 @@
>    */
>
>   #include <sys/types.h>
> -#include <sysfs/libsysfs.h>
> +#include <libudev.h>
>
>   #include <errno.h>
>   #include <stdbool.h>
> @@ -133,8 +133,8 @@ static int list_exported_devices(char *host)
>   	return 0;
>   }
>
> -static void print_device(char *busid, char *vendor, char *product,
> -			 bool parsable)
> +static void print_device(const char *busid, const char *vendor,
> +			 const char *product, bool parsable)
>   {
>   	if (parsable)
>   		printf("busid=%s#usbid=%.4s:%.4s#", busid, vendor, product);
> @@ -148,106 +148,71 @@ static void print_product_name(char *product_name, bool parsable)
>   		printf("   %s\n", product_name);
>   }
>
> -static void print_interface(char *busid, char *driver, bool parsable)
> -{
> -	if (parsable)
> -		printf("%s=%s#", busid, driver);
> -	else
> -		printf("%9s%s -> %s\n", "", busid, driver);
> -}
> -
> -static int is_device(void *x)
> -{
> -	struct sysfs_attribute *devpath;
> -	struct sysfs_device *dev = x;
> -	int ret = 0;
> -
> -	devpath = sysfs_get_device_attr(dev, "devpath");
> -	if (devpath && *devpath->value != '0')
> -		ret = 1;
> -
> -	return ret;
> -}
> -
> -static int devcmp(void *a, void *b)
> -{
> -	return strcmp(a, b);
> -}
> -
>   static int list_devices(bool parsable)
>   {
> -	char bus_type[] = "usb";
> -	char busid[SYSFS_BUS_ID_SIZE];
> +	struct udev *udev;
> +	struct udev_enumerate *enumerate;
> +	struct udev_list_entry *devices, *dev_list_entry;
> +	struct udev_device *dev;
> +	const char *path;
> +	const char *idVendor;
> +	const char *idProduct;
> +	const char *bConfValue;
> +	const char *bNumIntfs;
> +	const char *busid;
>   	char product_name[128];
> -	struct sysfs_bus *ubus;
> -	struct sysfs_device *dev;
> -	struct sysfs_device *intf;
> -	struct sysfs_attribute *idVendor;
> -	struct sysfs_attribute *idProduct;
> -	struct sysfs_attribute *bConfValue;
> -	struct sysfs_attribute *bNumIntfs;
> -	struct dlist *devlist;
> -	int i;
>   	int ret = -1;
>
> -	ubus = sysfs_open_bus(bus_type);
> -	if (!ubus) {
> -		err("could not open %s bus: %s", bus_type, strerror(errno));
> -		return -1;
> -	}
> -
> -	devlist = sysfs_get_bus_devices(ubus);
> -	if (!devlist) {
> -		err("could not get %s bus devices: %s", bus_type,
> -		    strerror(errno));
> -		goto err_out;
> -	}
> -
> -	/* remove interfaces and root hubs from device list */
> -	dlist_filter_sort(devlist, is_device, devcmp);
> -
> -	if (!parsable) {
> -		printf("Local USB devices\n");
> -		printf("=================\n");
> -	}
> -	dlist_for_each_data(devlist, dev, struct sysfs_device) {
> -		idVendor   = sysfs_get_device_attr(dev, "idVendor");
> -		idProduct  = sysfs_get_device_attr(dev, "idProduct");
> -		bConfValue = sysfs_get_device_attr(dev, "bConfigurationValue");
> -		bNumIntfs  = sysfs_get_device_attr(dev, "bNumInterfaces");
> +	/* Create libudev context. */
> +	udev = udev_new();
> +
> +	/* Create libudev device enumeration. */
> +	enumerate = udev_enumerate_new(udev);
> +
> +	/* Take only USB devices that are not hubs and do not have
> +	 * the bInterfaceNumber attribute, i.e. are not interfaces.
> +	 */
> +	udev_enumerate_add_match_subsystem(enumerate, "usb");
> +	udev_enumerate_add_nomatch_sysattr(enumerate, "bDeviceClass", "09");
> +	udev_enumerate_add_nomatch_sysattr(enumerate, "bInterfaceNumber", NULL);
> +	udev_enumerate_scan_devices(enumerate);
> +
> +	devices = udev_enumerate_get_list_entry(enumerate);
> +
> +	/* Show information about each device. */
> +	udev_list_entry_foreach(dev_list_entry, devices) {
> +		path = udev_list_entry_get_name(dev_list_entry);
> +		dev = udev_device_new_from_syspath(udev, path);
> +
> +		/* Get device information. */
> +		idVendor = udev_device_get_sysattr_value(dev, "idVendor");
> +		idProduct = udev_device_get_sysattr_value(dev, "idProduct");
> +		bConfValue = udev_device_get_sysattr_value(dev, "bConfigurationValue");
> +		bNumIntfs = udev_device_get_sysattr_value(dev, "bNumInterfaces");
> +		busid = udev_device_get_sysname(dev);
>   		if (!idVendor || !idProduct || !bConfValue || !bNumIntfs) {
> -			err("problem getting device attributes: %s",
> +			err("Problem getting device attributes: %s",
>   			    strerror(errno));
>   			goto err_out;
>   		}
>
> -		/* get product name */
> +		/* Get product name. */
>   		usbip_names_get_product(product_name, sizeof(product_name),
> -					strtol(idVendor->value, NULL, 16),
> -					strtol(idProduct->value, NULL, 16));
> -		print_device(dev->bus_id, idVendor->value, idProduct->value,
> -			     parsable);
> +					strtol(idVendor, NULL, 16),
> +					strtol(idProduct, NULL, 16));
> +
> +		/* Print information. */
> +		print_device(busid, idVendor, idProduct, parsable);
>   		print_product_name(product_name, parsable);
>
> -		for (i = 0; i < atoi(bNumIntfs->value); i++) {
> -			snprintf(busid, sizeof(busid), "%s:%.1s.%d",
> -				 dev->bus_id, bConfValue->value, i);
> -			intf = sysfs_open_device(bus_type, busid);
> -			if (!intf) {
> -				err("could not open device interface: %s",
> -				    strerror(errno));
> -				goto err_out;
> -			}
> -			print_interface(busid, intf->driver_name, parsable);
> -			sysfs_close_device(intf);
> -		}
>   		printf("\n");
> -	}
>
> -	ret = 0;
Do you need to delete this? Where does ret get set to 0 then?

> +		udev_device_unref(dev);
> +	}
>
>   err_out:
> -	sysfs_close_bus(ubus);
> +	udev_enumerate_unref(enumerate);
> +	udev_unref(udev);
>
>   	return ret;

Is ret = -1 still at this point?

>   }
>

-- Shuah

-- 
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
shuah.kh@samsung.com | (970) 672-0658

  reply	other threads:[~2014-03-06 20:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04 19:10 [PATCH 00/12] Migrate usbip-utils to libudev Valentina Manea
2014-03-04 19:10 ` [PATCH 01/12] staging: usbip: userspace: migrate usbip_bind " Valentina Manea
2014-03-05  9:42   ` Dan Carpenter
2014-03-05 10:15     ` Dan Carpenter
2014-03-06  6:17       ` Valentina Manea
2014-03-05  9:56   ` Dan Carpenter
2014-03-06 16:15   ` Shuah Khan
2014-03-06 18:19     ` Dan Carpenter
2014-03-04 19:10 ` [PATCH 02/12] staging: usbip: userspace: remove useless libsysfs includes Valentina Manea
2014-03-04 19:10 ` [PATCH 03/12] staging: usbip: userspace: migrate usbip_unbind to libudev Valentina Manea
2014-03-06 16:31   ` Shuah Khan
2014-03-04 19:10 ` [PATCH 04/12] staging: usbip: userspace: migrate usbip_list " Valentina Manea
2014-03-06 20:57   ` Shuah Khan [this message]
2014-03-04 19:10 ` [PATCH 05/12] staging: usbip: userspace: re-add interface information listing Valentina Manea
2014-03-06 21:11   ` Shuah Khan
2014-03-04 19:10 ` [PATCH 06/12] staging: usbip: userspace: add new list API Valentina Manea
2014-03-05  6:35   ` Greg KH
2014-03-05 10:16     ` Dan Carpenter
     [not found]       ` <CAByK=5bzS4R0sGj5w5x8gc8DcKXvnr58WskoShuq6G30YTsOgQ@mail.gmail.com>
2014-03-06 19:55         ` [firefly] " Greg KH
2014-03-04 19:10 ` [PATCH 07/12] staging: usbip: userspace: move sysfs_utils to libsrc Valentina Manea
2014-03-04 19:10 ` [PATCH 08/12] staging: usbip: userspace: migrate usbip_host_driver to libudev Valentina Manea
2014-03-06 21:43   ` Shuah Khan
2014-03-04 19:10 ` [PATCH 09/12] staging: usbip: userspace: remove class device infrastructure in vhci_driver Valentina Manea
2014-03-06 21:59   ` Shuah Khan
2014-03-04 19:10 ` [PATCH 10/12] staging: usbip: userspace: migrate vhci_driver to libudev Valentina Manea
2014-03-06 22:07   ` Shuah Khan
2014-03-04 19:10 ` [PATCH 11/12] staging: usbip: userspace: remove libsysfs flag and autoconf check Valentina Manea
2014-03-04 19:10 ` [PATCH 12/12] staging: usbip: userspace: update dependencies in README Valentina Manea
2014-03-05  6:37 ` [PATCH 00/12] Migrate usbip-utils to libudev Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5318E11D.7010106@samsung.com \
    --to=shuah.kh@samsung.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=dominik.paulus@fau.de \
    --cc=firefly@lists.rosedu.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ihadzic@research.bell-labs.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ly80toro@cip.cs.fau.de \
    --cc=tobias.polzer@fau.de \
    --cc=valentina.manea.m@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.