Re: [PATCH 07/11] HID: HIDp: remove duplicated coded
From: David Herrmann
Date: Mon Feb 03 2014 - 10:19:13 EST
Hi
On Mon, Feb 3, 2014 at 4:11 PM, Benjamin Tissoires
<benjamin.tissoires@xxxxxxxxx> wrote:
> On Mon, Feb 3, 2014 at 10:02 AM, David Herrmann <dh.herrmann@xxxxxxxxx> wrote:
>> Hi
>>
>> On Sun, Feb 2, 2014 at 5:50 AM, Benjamin Tissoires
>> <benjamin.tissoires@xxxxxxxxxx> wrote:
>>> - Move hidp_output_report() above
>>> - Removed duplicated code in hidp_output_raw_report()
>>>
>>> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@xxxxxxxxxx>
>>> ---
>>> net/bluetooth/hidp/core.c | 68 ++++++++---------------------------------------
>>> 1 file changed, 11 insertions(+), 57 deletions(-)
>>>
>>> diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
>>> index 469e61b..02670b3 100644
>>> --- a/net/bluetooth/hidp/core.c
>>> +++ b/net/bluetooth/hidp/core.c
>>> @@ -373,62 +373,25 @@ err:
>>> return ret;
>>> }
>>>
>>> -static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count,
>>> - unsigned char report_type)
>>> +static int hidp_output_report(struct hid_device *hid, __u8 *data, size_t count)
>>> {
>>> struct hidp_session *session = hid->driver_data;
>>> - int ret;
>>>
>>> + return hidp_send_intr_message(session,
>>> + HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT,
>>> + data, count);
>>> +}
>>> +
>>> +static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data,
>>> + size_t count, unsigned char report_type)
>>> +{
>>> if (report_type == HID_OUTPUT_REPORT) {
>>> - report_type = HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT;
>>> - return hidp_send_intr_message(session, report_type,
>>> - data, count);
>>> + return hidp_output_report(hid, data, count);
>>
>> NAK, that does not work with BT. hidp_output_raw_report() can do both,
>> a synchronous SET_REPORT and an async OUTPUT_REPORT. It's currently
>> screwed up, as for RTYPE_OUTPUT it uses the intr-channel, for
>> RTYPE_FEATURE the ctrl-channel.
>
> David, please, re-review it carefully, and see that there is _no_
> change in the code path with this refactoring:
> hidp_output_report() calls exactly one hidp_send_intr_message() with
> the same arguments.
>
> And for the rest, you will see that the code path is still the same also.
Sorry, my bad. I thought you changed hidp_output_raw_report() to call
hidp_output_report() unconditionally. You're indeed right, the
code-paths are the same and they now highlight the very horrible hack
hid_output_raw_report() has been in the past for HIDP.
Reviewed-by: David Herrmann <dh.herrmann@xxxxxxxxx>
Thanks
David
>>
>> This function is exactly the reason why we added raw_report() and
>> output_report(). So I'd like to keep it as it and just remove it once
>> we have no more users of hidp_output_raw_report().
>
> I worked on that yesterday, so I can make this happening soon (not
> today though).
>
> Cheers,
> Benjamin
>
>>
>> Thanks
>> David
>>
>>> } else if (report_type != HID_FEATURE_REPORT) {
>>> return -EINVAL;
>>> }
>>>
>>> - if (mutex_lock_interruptible(&session->report_mutex))
>>> - return -ERESTARTSYS;
>>> -
>>> - /* Set up our wait, and send the report request to the device. */
>>> - set_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags);
>>> - report_type = HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE;
>>> - ret = hidp_send_ctrl_message(session, report_type, data, count);
>>> - if (ret)
>>> - goto err;
>>> -
>>> - /* Wait for the ACK from the device. */
>>> - while (test_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags) &&
>>> - !atomic_read(&session->terminate)) {
>>> - int res;
>>> -
>>> - res = wait_event_interruptible_timeout(session->report_queue,
>>> - !test_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags)
>>> - || atomic_read(&session->terminate),
>>> - 10*HZ);
>>> - if (res == 0) {
>>> - /* timeout */
>>> - ret = -EIO;
>>> - goto err;
>>> - }
>>> - if (res < 0) {
>>> - /* signal */
>>> - ret = -ERESTARTSYS;
>>> - goto err;
>>> - }
>>> - }
>>> -
>>> - if (!session->output_report_success) {
>>> - ret = -EIO;
>>> - goto err;
>>> - }
>>> -
>>> - ret = count;
>>> -
>>> -err:
>>> - clear_bit(HIDP_WAITING_FOR_SEND_ACK, &session->flags);
>>> - mutex_unlock(&session->report_mutex);
>>> - return ret;
>>> + return hidp_set_raw_report(hid, data[0], data, count, report_type);
>>> }
>>>
>>> static int hidp_raw_request(struct hid_device *hid, unsigned char reportnum,
>>> @@ -445,15 +408,6 @@ static int hidp_raw_request(struct hid_device *hid, unsigned char reportnum,
>>> }
>>> }
>>>
>>> -static int hidp_output_report(struct hid_device *hid, __u8 *data, size_t count)
>>> -{
>>> - struct hidp_session *session = hid->driver_data;
>>> -
>>> - return hidp_send_intr_message(session,
>>> - HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT,
>>> - data, count);
>>> -}
>>> -
>>> static void hidp_idle_timeout(unsigned long arg)
>>> {
>>> struct hidp_session *session = (struct hidp_session *) arg;
>>> --
>>> 1.8.3.1
>>>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/