From patchwork Mon Feb 16 17:12:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Ospite X-Patchwork-Id: 5834171 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F36979F37F for ; Mon, 16 Feb 2015 17:12:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3CB4920121 for ; Mon, 16 Feb 2015 17:12:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 654F92024C for ; Mon, 16 Feb 2015 17:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753096AbbBPRMo (ORCPT ); Mon, 16 Feb 2015 12:12:44 -0500 Received: from smtp209.alice.it ([82.57.200.105]:30646 "EHLO smtp209.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753463AbbBPRMn (ORCPT ); Mon, 16 Feb 2015 12:12:43 -0500 Received: from jcn (87.3.192.150) by smtp209.alice.it (8.6.060.28) id 547E30250ACE2EF6; Mon, 16 Feb 2015 18:12:41 +0100 Received: from ao2 by jcn with local (Exim 4.84) (envelope-from ) id 1YNPDp-0003MX-3Z; Mon, 16 Feb 2015 18:12:37 +0100 From: Antonio Ospite To: linux-input@vger.kernel.org Cc: Antonio Ospite , Jiri Kosina , Lauri Kasanen , Frank Praznik Subject: [PATCH 3/5] HID: sony: Don't use magic numbers in sixaxis_set_operational_usb() Date: Mon, 16 Feb 2015 18:12:22 +0100 Message-Id: <1424106744-12872-4-git-send-email-ao2@ao2.it> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1424106744-12872-1-git-send-email-ao2@ao2.it> References: <20150216150659.db522f3d.cand@gmx.com> <1424106744-12872-1-git-send-email-ao2@ao2.it> X-Face: z*RaLf`X<@C75u6Ig9}{oW$H; 1_\2t5)({*|jhM/Vb; ]yA5\I~93>J<_`<4)A{':UrE Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove the magic numbers used in sixaxis_set_operational_usb(): - use the already defined SIXAXIS_REPORT_0xF2_SIZE; - define and use SIXAXIS_REPORT_0xF5_SIZE; - set the dummy buffer size to accommodate any report that is going to be requested. Signed-off-by: Antonio Ospite --- drivers/hid/hid-sony.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 303335b..a419868 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -803,6 +803,7 @@ union sixaxis_output_report_01 { #define DS4_REPORT_0x11_SIZE 78 #define DS4_REPORT_0x81_SIZE 7 #define SIXAXIS_REPORT_0xF2_SIZE 17 +#define SIXAXIS_REPORT_0xF5_SIZE 8 static spinlock_t sony_dev_list_lock; static LIST_HEAD(sony_device_list); @@ -1131,13 +1132,15 @@ static void sony_input_configured(struct hid_device *hdev, static int sixaxis_set_operational_usb(struct hid_device *hdev) { int ret; - char *buf = kmalloc(18, GFP_KERNEL); + const int buf_size = + max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE); + char *buf = kmalloc(buf_size, GFP_KERNEL); if (!buf) return -ENOMEM; - ret = hid_hw_raw_request(hdev, 0xf2, buf, 17, HID_FEATURE_REPORT, - HID_REQ_GET_REPORT); + ret = hid_hw_raw_request(hdev, 0xf2, buf, SIXAXIS_REPORT_0xF2_SIZE, + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); if (ret < 0) { hid_err(hdev, "can't set operational mode: step 1\n"); @@ -1148,8 +1151,8 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev) * Some compatible controllers like the Speedlink Strike FX and * Gasia need another query plus an USB interrupt to get operational. */ - ret = hid_hw_raw_request(hdev, 0xf5, buf, 8, HID_FEATURE_REPORT, - HID_REQ_GET_REPORT); + ret = hid_hw_raw_request(hdev, 0xf5, buf, SIXAXIS_REPORT_0xF5_SIZE, + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); if (ret < 0) { hid_err(hdev, "can't set operational mode: step 2\n");