From patchwork Wed Apr 8 20:56:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Michal_Mal=C3=BD?= X-Patchwork-Id: 6182621 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0DEBABF4A6 for ; Wed, 8 Apr 2015 20:57:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0CB8E20386 for ; Wed, 8 Apr 2015 20:57:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 125AE2038F for ; Wed, 8 Apr 2015 20:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754774AbbDHU5c (ORCPT ); Wed, 8 Apr 2015 16:57:32 -0400 Received: from transparentnimenzy.cz ([31.31.77.140]:33016 "EHLO smtp.devoid-pointer.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753278AbbDHU52 (ORCPT ); Wed, 8 Apr 2015 16:57:28 -0400 Received: from Labrat.localdomain.localdomain (228.123.broadband5.iol.cz [88.100.123.228]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by smtp.devoid-pointer.net (Postfix) with ESMTPSA id 3DFD221A8C; Wed, 8 Apr 2015 22:57:18 +0200 (CEST) From: =?UTF-8?q?Michal=20Mal=C3=BD?= To: jkosina@suse.cz Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.or, elias.vds@gmail.com, simon@mungewell.org, =?UTF-8?q?Michal=20Mal=C3=BD?= Subject: [PATCH v2 12/15] HID: hid-lg4ff: Constify those members of lg4ff_device_entry struct whose value is not supposed to change. Date: Wed, 8 Apr 2015 22:56:50 +0200 Message-Id: <1428526613-24239-13-git-send-email-madcatxster@devoid-pointer.net> X-Mailer: git-send-email 2.3.5 In-Reply-To: <1428526613-24239-1-git-send-email-madcatxster@devoid-pointer.net> References: <1428526613-24239-1-git-send-email-madcatxster@devoid-pointer.net> MIME-Version: 1.0 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 Constify those members of lg4ff_device_entry struct whose value is not supposed to change. Signed-off-by: Michal MalĂ˝ --- drivers/hid/hid-lg4ff.c | 54 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index d27b210..dcaf481 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -72,18 +72,18 @@ static void lg4ff_set_range_dfp(struct hid_device *hid, u16 range); static void lg4ff_set_range_g25(struct hid_device *hid, u16 range); struct lg4ff_wheel_data { - u32 product_id; + const u32 product_id; u16 range; - u16 min_range; - u16 max_range; + const u16 min_range; + const u16 max_range; #ifdef CONFIG_LEDS_CLASS u8 led_state; struct led_classdev *led[5]; #endif - u32 alternate_modes; - const char *real_tag; - const char *real_name; - u16 real_product_id; + const u32 alternate_modes; + const char * const real_tag; + const char * const real_name; + const u16 real_product_id; void (*set_range)(struct hid_device *hid, u16 range); }; @@ -300,6 +300,34 @@ int lg4ff_adjust_input_event(struct hid_device *hid, struct hid_field *field, } } +static void lg4ff_init_wheel_data(struct lg4ff_wheel_data * const wdata, const struct lg4ff_wheel *wheel, + const struct lg4ff_multimode_wheel *mmode_wheel, + const u16 real_product_id) +{ + u32 alternate_modes = 0; + const char *real_tag = NULL; + const char *real_name = NULL; + + if (mmode_wheel) { + alternate_modes = mmode_wheel->alternate_modes; + real_tag = mmode_wheel->real_tag; + real_name = mmode_wheel->real_name; + } + + { + struct lg4ff_wheel_data t_wdata = { .product_id = wheel->product_id, + .real_product_id = real_product_id, + .min_range = wheel->min_range, + .max_range = wheel->max_range, + .set_range = wheel->set_range, + .alternate_modes = alternate_modes, + .real_tag = real_tag, + .real_name = real_name }; + + memcpy(wdata, &t_wdata, sizeof(t_wdata)); + } +} + static int lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *effect) { struct hid_device *hid = input_get_drvdata(dev); @@ -1102,6 +1130,7 @@ int lg4ff_init(struct hid_device *hid) struct hid_report *report = list_entry(report_list->next, struct hid_report, list); const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor); const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice); + const struct lg4ff_multimode_wheel *mmode_wheel = NULL; struct lg4ff_device_entry *entry; struct lg_drv_data *drv_data; int error, i, j; @@ -1177,17 +1206,12 @@ int lg4ff_init(struct hid_device *hid) if (error) goto err_init; - entry->wdata.product_id = lg4ff_devices[i].product_id; - entry->wdata.real_product_id = real_product_id; - entry->wdata.min_range = lg4ff_devices[i].min_range; - entry->wdata.max_range = lg4ff_devices[i].max_range; - entry->wdata.set_range = lg4ff_devices[i].set_range; + /* Initialize device properties */ if (mmode_ret == LG4FF_MMODE_IS_MULTIMODE) { BUG_ON(mmode_idx == -1); - entry->wdata.alternate_modes = lg4ff_multimode_wheels[mmode_idx].alternate_modes; - entry->wdata.real_tag = lg4ff_multimode_wheels[mmode_idx].real_tag; - entry->wdata.real_name = lg4ff_multimode_wheels[mmode_idx].real_name; + mmode_wheel = &lg4ff_multimode_wheels[mmode_idx]; } + lg4ff_init_wheel_data(&entry->wdata, &lg4ff_devices[i], mmode_wheel, real_product_id); /* Check if autocentering is available and * set the centering force to zero by default */