From: Szymon Janc <szymon.janc@gmail.com>
To: Antonio Ospite <ao2@ao2.it>
Cc: linux-bluetooth@vger.kernel.org,
Bastien Nocera <hadess@hadess.net>,
Frank Praznik <frank.praznik@oh.rr.com>
Subject: Re: [PATCH BlueZ 1/5] plugins/sixaxis: simplify get_js_numbers()
Date: Wed, 07 May 2014 21:57:49 +0200 [thread overview]
Message-ID: <1503255.GchojqlcyW@athlon> (raw)
In-Reply-To: <1399370776-5027-2-git-send-email-ao2@ao2.it>
Hi Antonio,
On Tuesday 06 May 2014 12:06:12 Antonio Ospite wrote:
Just a nitpick :) we usually start commit summary with capital letter eg.
"plugins/sixaxis: Simplify get_js_numbers function"
Same goes to rest of commits in this series.
> Use udev_enumerate_add_match_parent() to simplify get_js_number() a lot,
> with this mechanism the old JOIN-like operation to find joystick nodes
> is no longer necessary.
>
> Also require libudev >= 172, this is where
> udev_enumerate_add_match_parent() has been first introduced.
This should be fine, any distro shipping BlueZ 5 is most likely already
providing newer version of udev anyway.
>
> NOTE: using udev_enumerate_add_match_parent() results in a memory leak
> when enumerating child devices, this has been fixed in udev 207; the
> commit which fixes the issue is this one:
> http://cgit.freedesktop.org/systemd/systemd/commit/?id=51cc07576e119dea6e654
> 78eeba9472979fd0936 ---
> configure.ac | 4 +--
> plugins/sixaxis.c | 92
> +++++++++++++++++++++++++++---------------------------- 2 files changed, 47
> insertions(+), 49 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 54a387f..4208ad8 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -125,8 +125,8 @@ AM_CONDITIONAL(MONITOR, test "${enable_monitor}" !=
> "no") AC_ARG_ENABLE(udev, AC_HELP_STRING([--disable-udev],
> [disable udev device support]), [enable_udev=${enableval}])
> if (test "${enable_tools}" != "no" && test "${enable_udev}" != "no"); then
> - PKG_CHECK_MODULES(UDEV, libudev >= 143, dummy=yes,
> - AC_MSG_ERROR(libudev >= 143 is required))
> + PKG_CHECK_MODULES(UDEV, libudev >= 172, dummy=yes,
> + AC_MSG_ERROR(libudev >= 172 is required))
> AC_SUBST(UDEV_CFLAGS)
> AC_SUBST(UDEV_LIBS)
> AC_CHECK_LIB(udev, udev_hwdb_new,
> diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c
> index 8045448..9db14ec 100644
> --- a/plugins/sixaxis.c
> +++ b/plugins/sixaxis.c
> @@ -235,62 +235,60 @@ static bool setup_device(int fd, int index, struct
> btd_adapter *adapter)
>
> static int get_js_number(struct udev_device *udevice)
> {
> - struct udev_list_entry *devices, *dev_list_entry;
> + struct udev_list_entry *dev_list_entry;
> struct udev_enumerate *enumerate;
> struct udev_device *hid_parent;
> - const char *hidraw_node;
> - const char *hid_phys;
> + struct udev_device *transport_parent;
> + struct udev_device *js_dev;
> + const char *js_devname;
> int number = 0;
>
> - hid_parent = udev_device_get_parent_with_subsystem_devtype(udevice,
> - "hid", NULL);
> -
> - hid_phys = udev_device_get_property_value(hid_parent, "HID_PHYS");
> - hidraw_node = udev_device_get_devnode(udevice);
> - if (!hid_phys || !hidraw_node)
> - return 0;
> + /*
> + * Go up by two levels from the hidraw device in order to support
> + * older kernels, where the hierachy of HID devices is different than
> + * newer kernels:
> + *
> + * - on kernels < 3.14 the input device is child of the transport
> + * device (usbhid, hidp):
> + *
> + * USB/BT
> + * |- hid
> + * | `- hidraw *
> + * `- input
> + * `- js
> + *
> + * - on kernels >= 3.14 the input device is child of the hid device
> + * itself, as it should be:
> + *
> + * USB/BT
> + * `- hid
> + * |- hidraw *
> + * `- input
> + * `- js
> + */
> + hid_parent = udev_device_get_parent(udevice);
> + transport_parent = udev_device_get_parent(hid_parent);
>
> enumerate = udev_enumerate_new(udev_device_get_udev(udevice));
> + udev_enumerate_add_match_parent(enumerate, transport_parent);
> udev_enumerate_add_match_sysname(enumerate, "js*");
> udev_enumerate_scan_devices(enumerate);
> - devices = udev_enumerate_get_list_entry(enumerate);
> -
> - udev_list_entry_foreach(dev_list_entry, devices) {
> - struct udev_device *input_parent;
> - struct udev_device *js_dev;
> - const char *input_phys;
> - const char *devname;
> -
> - devname = udev_list_entry_get_name(dev_list_entry);
> - js_dev = udev_device_new_from_syspath(
> - udev_device_get_udev(udevice),
> - devname);
> -
> - input_parent = udev_device_get_parent_with_subsystem_devtype(
> - js_dev, "input", NULL);
> - if (!input_parent)
> - goto next;
> -
> - /* check if this is the joystick relative to the hidraw device
> - * above */
> - input_phys = udev_device_get_sysattr_value(input_parent,
> - "phys");
> - if (!input_phys)
> - goto next;
> -
> - if (!strcmp(input_phys, hid_phys)) {
> - number = atoi(udev_device_get_sysnum(js_dev));
> -
> - /* joystick numbers start from 0, leds from 1 */
> - number++;
> -
> - udev_device_unref(js_dev);
> - break;
> - }
> -next:
> - udev_device_unref(js_dev);
> - }
>
> + /* get the first js* device, there should be only one anyway */
> + dev_list_entry = udev_enumerate_get_list_entry(enumerate);
> +
> + if (dev_list_entry == NULL)
if (!dev_list_entry) ...
> + return number;
> +
> + js_devname = udev_list_entry_get_name(dev_list_entry);
> + js_dev = udev_device_new_from_syspath(
> + udev_device_get_udev(udevice),
> + js_devname);
Indentation issue here.
> +
> + /* joystick numbers start from 0, leds from 1 */
> + number = atoi(udev_device_get_sysnum(js_dev)) + 1;
> +
> + udev_device_unref(js_dev);
> udev_enumerate_unref(enumerate);
>
> return number;
--
Szymon K. Janc
szymon.janc@gmail.com
next prev parent reply other threads:[~2014-05-07 19:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-06 10:06 [PATCH BlueZ 0/5] plugin/sixaxis: use the sysfs leds class Antonio Ospite
2014-05-06 10:06 ` [PATCH BlueZ 1/5] plugins/sixaxis: simplify get_js_numbers() Antonio Ospite
2014-05-07 19:57 ` Szymon Janc [this message]
2014-05-06 10:06 ` [PATCH BlueZ 2/5] plugins/sixaxis: factor out a set_leds_hidraw() function Antonio Ospite
2014-05-07 19:58 ` Szymon Janc
2014-05-06 10:06 ` [PATCH BlueZ 3/5] plugins/sixaxis: factor out a calc_leds_bitmap() function Antonio Ospite
2014-05-07 19:59 ` Szymon Janc
2014-05-06 10:06 ` [PATCH BlueZ 4/5] plugins/sixaxis: add a get_leds_data() function Antonio Ospite
2014-05-07 20:04 ` Szymon Janc
2014-05-09 12:22 ` Johan Hedberg
2014-05-09 13:31 ` Antonio Ospite
2014-05-06 10:06 ` [PATCH BlueZ 5/5] plugins/sixaxis: add a set_leds_sysfs() function Antonio Ospite
2014-05-07 20:24 ` Szymon Janc
2014-05-14 21:40 ` [PATCHv2 BlueZ 0/5] plugin/sixaxis: Set leds using the sysfs leds class Antonio Ospite
2014-05-14 21:40 ` [PATCHv2 BlueZ 2/5] plugins/sixaxis: Factor out a set_leds_hidraw() function Antonio Ospite
2014-05-14 21:40 ` [PATCHv2 BlueZ 3/5] plugins/sixaxis: Factor out a calc_leds_bitmap() function Antonio Ospite
2014-05-14 21:40 ` [PATCHv2 BlueZ 4/5] plugins/sixaxis: Add a get_leds_data() function Antonio Ospite
2014-05-15 20:25 ` Szymon Janc
2014-05-16 8:13 ` Antonio Ospite
2014-05-14 21:40 ` [PATCHv2 BlueZ 5/5] plugins/sixaxis: Add a set_leds_sysfs() function Antonio Ospite
2014-05-15 20:25 ` Szymon Janc
2014-05-15 15:28 ` [PATCHv2 BlueZ 0/5] plugin/sixaxis: Set leds using the sysfs leds class Frank Praznik
2014-05-15 16:33 ` Antonio Ospite
2014-05-16 12:37 ` Szymon Janc
2014-05-27 11:25 ` [PATCHv3 " Antonio Ospite
2014-05-27 11:25 ` [PATCHv3 BlueZ 4/5] plugins/sixaxis: Add a get_leds_data() function Antonio Ospite
2014-05-27 11:25 ` [PATCHv3 BlueZ 5/5] plugins/sixaxis: Add a set_leds_sysfs() function Antonio Ospite
2014-06-08 12:58 ` [PATCHv3 BlueZ 0/5] plugin/sixaxis: Set leds using the sysfs leds class Szymon Janc
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=1503255.GchojqlcyW@athlon \
--to=szymon.janc@gmail.com \
--cc=ao2@ao2.it \
--cc=frank.praznik@oh.rr.com \
--cc=hadess@hadess.net \
--cc=linux-bluetooth@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).