From patchwork Fri Nov 26 19:57:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Achatz X-Patchwork-Id: 359792 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAQJwUxY017599 for ; Fri, 26 Nov 2010 19:58:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752043Ab0KZT6N (ORCPT ); Fri, 26 Nov 2010 14:58:13 -0500 Received: from mail-in-10.arcor-online.net ([151.189.21.50]:55481 "EHLO mail-in-10.arcor-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751697Ab0KZT5l (ORCPT ); Fri, 26 Nov 2010 14:57:41 -0500 Received: from mail-in-20-z2.arcor-online.net (mail-in-20-z2.arcor-online.net [151.189.8.85]) by mx.arcor.de (Postfix) with ESMTP id 0E3792D6736; Fri, 26 Nov 2010 20:57:40 +0100 (CET) Received: from mail-in-01.arcor-online.net (mail-in-01.arcor-online.net [151.189.21.41]) by mail-in-20-z2.arcor-online.net (Postfix) with ESMTP id 085CEE9C3D; Fri, 26 Nov 2010 20:57:40 +0100 (CET) Received: from [192.168.0.7] (dslb-088-067-007-010.pools.arcor-ip.net [88.67.7.10]) (Authenticated sender: screamingfist@arcor.de) by mail-in-01.arcor-online.net (Postfix) with ESMTPSA id 2B9B55A1E0; Fri, 26 Nov 2010 20:57:39 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-01.arcor-online.net 2B9B55A1E0 Subject: [PATCH 4/5] HID: roccat: Reducing number of functions in kone and pyra drivers From: Stefan Achatz Reply-To: erazor_de@users.sourceforge.net To: Randy Dunlap , Greg Kroah-Hartman , Jiri Kosina , Stefan Achatz , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org Date: Fri, 26 Nov 2010 20:57:38 +0100 Message-ID: <1290801458.18750.165.camel@neuromancer> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 (2.30.3-1.fc13) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 26 Nov 2010 19:58:31 +0000 (UTC) diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index a837b8a..005a7be 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c @@ -35,6 +35,8 @@ #include "hid-roccat.h" #include "hid-roccat-kone.h" +static uint profile_numbers[5] = {0, 1, 2, 3, 4}; + /* kone_class is used for creating sysfs attributes via roccat char device */ static struct class *kone_class; @@ -324,9 +326,9 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, return sizeof(struct kone_settings); } -static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count, int number) { +static ssize_t kone_sysfs_read_profilex(struct file *fp, + struct kobject *kobj, struct bin_attribute *attr, + char *buf, loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj)->parent->parent; struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); @@ -338,46 +340,16 @@ static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, count = sizeof(struct kone_profile) - off; mutex_lock(&kone->kone_lock); - memcpy(buf, ((char const *)&kone->profiles[number - 1]) + off, count); + memcpy(buf, ((char const *)&kone->profiles[*(uint *)(attr->private)]) + off, count); mutex_unlock(&kone->kone_lock); return count; } -static ssize_t kone_sysfs_read_profile1(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 1); -} - -static ssize_t kone_sysfs_read_profile2(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 2); -} - -static ssize_t kone_sysfs_read_profile3(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 3); -} - -static ssize_t kone_sysfs_read_profile4(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 4); -} - -static ssize_t kone_sysfs_read_profile5(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_read_profilex(kobj, attr, buf, off, count, 5); -} - /* Writes data only if different to stored data */ -static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count, int number) { +static ssize_t kone_sysfs_write_profilex(struct file *fp, + struct kobject *kobj, struct bin_attribute *attr, + char *buf, loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj)->parent->parent; struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); @@ -389,13 +361,14 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, if (off != 0 || count != sizeof(struct kone_profile)) return -EINVAL; - profile = &kone->profiles[number - 1]; + profile = &kone->profiles[*(uint *)(attr->private)]; mutex_lock(&kone->kone_lock); difference = memcmp(buf, profile, sizeof(struct kone_profile)); if (difference) { retval = kone_set_profile(usb_dev, - (struct kone_profile const *)buf, number); + (struct kone_profile const *)buf, + *(uint *)(attr->private) + 1); if (!retval) memcpy(profile, buf, sizeof(struct kone_profile)); } @@ -407,36 +380,6 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj, return sizeof(struct kone_profile); } -static ssize_t kone_sysfs_write_profile1(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 1); -} - -static ssize_t kone_sysfs_write_profile2(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 2); -} - -static ssize_t kone_sysfs_write_profile3(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 3); -} - -static ssize_t kone_sysfs_write_profile4(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 4); -} - -static ssize_t kone_sysfs_write_profile5(struct file *fp, struct kobject *kobj, - struct bin_attribute *attr, char *buf, - loff_t off, size_t count) { - return kone_sysfs_write_profilex(kobj, attr, buf, off, count, 5); -} - static ssize_t kone_sysfs_show_actual_profile(struct device *dev, struct device_attribute *attr, char *buf) { @@ -692,32 +635,37 @@ static struct bin_attribute kone_bin_attributes[] = { { .attr = { .name = "profile1", .mode = 0660 }, .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profile1, - .write = kone_sysfs_write_profile1 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[0] }, { .attr = { .name = "profile2", .mode = 0660 }, .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profile2, - .write = kone_sysfs_write_profile2 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[1] }, { .attr = { .name = "profile3", .mode = 0660 }, .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profile3, - .write = kone_sysfs_write_profile3 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[2] }, { .attr = { .name = "profile4", .mode = 0660 }, .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profile4, - .write = kone_sysfs_write_profile4 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[3] }, { .attr = { .name = "profile5", .mode = 0660 }, .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profile5, - .write = kone_sysfs_write_profile5 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[4] }, __ATTR_NULL }; diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index a50c89e..5ce0580 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c @@ -27,6 +27,8 @@ #include "hid-roccat.h" #include "hid-roccat-pyra.h" +static uint profile_numbers[5] = {0, 1, 2, 3, 4}; + /* pyra_class is used for creating sysfs attributes via roccat char device */ static struct class *pyra_class; @@ -224,7 +226,7 @@ static int pyra_set_settings(struct usb_device *usb_dev, static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count, int number) + loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj)->parent->parent; @@ -237,56 +239,16 @@ static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, count = sizeof(struct pyra_profile_settings) - off; mutex_lock(&pyra->pyra_lock); - memcpy(buf, ((char const *)&pyra->profile_settings[number]) + off, + memcpy(buf, ((char const *)&pyra->profile_settings[*(uint *)(attr->private)]) + off, count); mutex_unlock(&pyra->pyra_lock); return count; } -static ssize_t pyra_sysfs_read_profile1_settings(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_settings(fp, kobj, - attr, buf, off, count, 0); -} - -static ssize_t pyra_sysfs_read_profile2_settings(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_settings(fp, kobj, - attr, buf, off, count, 1); -} - -static ssize_t pyra_sysfs_read_profile3_settings(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_settings(fp, kobj, - attr, buf, off, count, 2); -} - -static ssize_t pyra_sysfs_read_profile4_settings(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_settings(fp, kobj, - attr, buf, off, count, 3); -} - -static ssize_t pyra_sysfs_read_profile5_settings(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_settings(fp, kobj, - attr, buf, off, count, 4); -} - static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count, int number) + loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj)->parent->parent; @@ -299,53 +261,13 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, count = sizeof(struct pyra_profile_buttons) - off; mutex_lock(&pyra->pyra_lock); - memcpy(buf, ((char const *)&pyra->profile_buttons[number]) + off, + memcpy(buf, ((char const *)&pyra->profile_buttons[*(uint *)(attr->private)]) + off, count); mutex_unlock(&pyra->pyra_lock); return count; } -static ssize_t pyra_sysfs_read_profile1_buttons(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_buttons(fp, kobj, - attr, buf, off, count, 0); -} - -static ssize_t pyra_sysfs_read_profile2_buttons(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_buttons(fp, kobj, - attr, buf, off, count, 1); -} - -static ssize_t pyra_sysfs_read_profile3_buttons(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_buttons(fp, kobj, - attr, buf, off, count, 2); -} - -static ssize_t pyra_sysfs_read_profile4_buttons(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_buttons(fp, kobj, - attr, buf, off, count, 3); -} - -static ssize_t pyra_sysfs_read_profile5_buttons(struct file *fp, - struct kobject *kobj, struct bin_attribute *attr, char *buf, - loff_t off, size_t count) -{ - return pyra_sysfs_read_profilex_buttons(fp, kobj, - attr, buf, off, count, 4); -} - static ssize_t pyra_sysfs_write_profile_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) @@ -526,27 +448,32 @@ static struct bin_attribute pyra_bin_attributes[] = { { .attr = { .name = "profile1_settings", .mode = 0440 }, .size = sizeof(struct pyra_profile_settings), - .read = pyra_sysfs_read_profile1_settings + .read = pyra_sysfs_read_profilex_settings, + .private = &profile_numbers[0] }, { .attr = { .name = "profile2_settings", .mode = 0440 }, .size = sizeof(struct pyra_profile_settings), - .read = pyra_sysfs_read_profile2_settings + .read = pyra_sysfs_read_profilex_settings, + .private = &profile_numbers[1] }, { .attr = { .name = "profile3_settings", .mode = 0440 }, .size = sizeof(struct pyra_profile_settings), - .read = pyra_sysfs_read_profile3_settings + .read = pyra_sysfs_read_profilex_settings, + .private = &profile_numbers[2] }, { .attr = { .name = "profile4_settings", .mode = 0440 }, .size = sizeof(struct pyra_profile_settings), - .read = pyra_sysfs_read_profile4_settings + .read = pyra_sysfs_read_profilex_settings, + .private = &profile_numbers[3] }, { .attr = { .name = "profile5_settings", .mode = 0440 }, .size = sizeof(struct pyra_profile_settings), - .read = pyra_sysfs_read_profile5_settings + .read = pyra_sysfs_read_profilex_settings, + .private = &profile_numbers[4] }, { .attr = { .name = "profile_buttons", .mode = 0220 }, @@ -556,27 +483,32 @@ static struct bin_attribute pyra_bin_attributes[] = { { .attr = { .name = "profile1_buttons", .mode = 0440 }, .size = sizeof(struct pyra_profile_buttons), - .read = pyra_sysfs_read_profile1_buttons + .read = pyra_sysfs_read_profilex_buttons, + .private = &profile_numbers[0] }, { .attr = { .name = "profile2_buttons", .mode = 0440 }, .size = sizeof(struct pyra_profile_buttons), - .read = pyra_sysfs_read_profile2_buttons + .read = pyra_sysfs_read_profilex_buttons, + .private = &profile_numbers[1] }, { .attr = { .name = "profile3_buttons", .mode = 0440 }, .size = sizeof(struct pyra_profile_buttons), - .read = pyra_sysfs_read_profile3_buttons + .read = pyra_sysfs_read_profilex_buttons, + .private = &profile_numbers[2] }, { .attr = { .name = "profile4_buttons", .mode = 0440 }, .size = sizeof(struct pyra_profile_buttons), - .read = pyra_sysfs_read_profile4_buttons + .read = pyra_sysfs_read_profilex_buttons, + .private = &profile_numbers[3] }, { .attr = { .name = "profile5_buttons", .mode = 0440 }, .size = sizeof(struct pyra_profile_buttons), - .read = pyra_sysfs_read_profile5_buttons + .read = pyra_sysfs_read_profilex_buttons, + .private = &profile_numbers[4] }, { .attr = { .name = "settings", .mode = 0660 },