···514514 */
515515516516static bool
517517+find_xdev_name_from_pairs(const struct xrt_device *xdev,
518518+ const struct xrt_binding_profile *xbp,
519519+ enum xrt_input_name from_name,
520520+ enum xrt_input_name *out_name)
521521+{
522522+ if (from_name == 0) {
523523+ *out_name = 0;
524524+ return true; // Not asking for anything, just keep going.
525525+ }
526526+527527+ /*
528528+ * For asymmetrical devices like PS Sense being re-bound to a symmetrical
529529+ * "device" like simple controller can be problemantic as depending on
530530+ * which hand it is menu is bound to different inputs. Instead of making
531531+ * the driver have two completely unique binding mappings per hand, we
532532+ * instead loop over all pairs finding the first match. In other words
533533+ * this means there can be multiple of the same 'from' value in the
534534+ * array of input pairs.
535535+ */
536536+ for (size_t i = 0; i < xbp->input_count; i++) {
537537+ if (from_name != xbp->inputs[i].from) {
538538+ continue;
539539+ }
540540+541541+ // What is the name on the xdev?
542542+ enum xrt_input_name xdev_name = xbp->inputs[i].device;
543543+544544+ // See if we can't find it.
545545+ for (uint32_t k = 0; k < xdev->input_count; k++) {
546546+ if (xdev->inputs[k].name == xdev_name) {
547547+ *out_name = xdev_name;
548548+ return true;
549549+ }
550550+ }
551551+ }
552552+553553+ return false;
554554+}
555555+556556+static bool
517557do_inputs(struct oxr_binding *binding_point,
518558 struct xrt_device *xdev,
519559 struct xrt_binding_profile *xbp,
···522562 uint32_t *input_count)
523563{
524564 enum xrt_input_name name = 0;
525525- if (xbp == NULL) {
526526- name = binding_point->input;
527527- } else {
528528- for (size_t i = 0; i < xbp->input_count; i++) {
529529- if (binding_point->input != xbp->inputs[i].from) {
530530- continue;
531531- }
565565+ enum xrt_input_name dpad_activate_name = 0;
532566533533- // We have found a device mapping.
534534- name = xbp->inputs[i].device;
535535- break;
536536- }
567567+ if (xbp != NULL) {
568568+ bool t1 = find_xdev_name_from_pairs(xdev, xbp, binding_point->input, &name);
569569+ bool t2 = find_xdev_name_from_pairs(xdev, xbp, binding_point->dpad_activate, &dpad_activate_name);
537570538538- // Didn't find a mapping.
539539- if (name == 0) {
571571+ // We couldn't find the needed inputs on the device.
572572+ if (!t1 || !t2) {
540573 return false;
541574 }
575575+ } else {
576576+ name = binding_point->input;
577577+ dpad_activate_name = binding_point->dpad_activate;
542578 }
543579544580 struct xrt_input *input = NULL;
545545- if (oxr_xdev_find_input(xdev, name, &input)) {
546546- uint32_t index = (*input_count)++;
547547- inputs[index].input = input;
548548- inputs[index].xdev = xdev;
549549- inputs[index].bound_path = matched_path;
550550- if (binding_point->dpad_activate != 0) {
551551- struct xrt_input *dpad_activate = NULL;
552552- if (!oxr_xdev_find_input(xdev, binding_point->dpad_activate, &dpad_activate)) {
553553- return false;
554554- }
555555- inputs[index].dpad_activate_name = binding_point->dpad_activate;
556556- inputs[index].dpad_activate = dpad_activate;
581581+ struct xrt_input *dpad_activate_input = NULL;
582582+583583+ // Early out if there is no such input.
584584+ if (!oxr_xdev_find_input(xdev, name, &input)) {
585585+ return false;
586586+ }
587587+588588+ // Check this before allocating an input.
589589+ if (dpad_activate_name != 0) {
590590+ if (!oxr_xdev_find_input(xdev, dpad_activate_name, &dpad_activate_input)) {
591591+ return false;
557592 }
558558- return true;
559593 }
560594561561- return false;
595595+ uint32_t index = (*input_count)++;
596596+ inputs[index].input = input;
597597+ inputs[index].xdev = xdev;
598598+ inputs[index].bound_path = matched_path;
599599+ if (dpad_activate_input != NULL) {
600600+ inputs[index].dpad_activate_name = dpad_activate_name;
601601+ inputs[index].dpad_activate = dpad_activate_input;
602602+ }
603603+604604+ return true;
562605}
563606564607static bool