# Re: \[PATCH v3\] HID: Add support for Sony PS3 BD Remote Control

- From: David Dillow \<dave@thedillows.org\>
- Date: 2012-09-25 14:43:05 
- List: linux-bluetooth
- Page: https://ratatoskr.run/linux-bluetooth/2012/09/8920305
- Thread: https://ratatoskr.run/linux-bluetooth/2012/09/8920300/t.md

```text
On Tue, 2012-09-25 at 16:30 +0200, Antonio Ospite wrote:
> +static int ps3remote_mapping(struct hid_device *hdev, struct hid_input *hi,
> +			     struct hid_field *field, struct hid_usage *usage,
> +			     unsigned long **bit, int *max)
> +{
> +	unsigned int key = usage->hid & HID_USAGE;

The size check below should be moved into the switch statement, and
modified for each, as you could access beyond the joypad_buttons array
as-is. The usage page check can stay outside the switch.

> +	if ((usage->hid & HID_USAGE_PAGE) != HID_UP_BUTTON ||
> +	    key >= ARRAY_SIZE(ps3remote_keymap_remote_buttons))
> +		return -1;
> +
> +	switch (usage->collection_index) {
> +	case 1:
> +		key = ps3remote_keymap_joypad_buttons[key];
> +		if (!key)
> +			return -1;
> +		break;
> +	case 2:
> +		key = ps3remote_keymap_remote_buttons[key];
> +		if (!key)
> +			return -1;
> +		break;
> +	default:
> +		return -1;
> +	}
> +
> +	hid_map_usage_clear(hi, usage, bit, max, EV_KEY, key);
> +	return 1;
> +}

```
