linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Achatz <erazor_de@users.sourceforge.net>
To: Jiri Kosina <jkosina@suse.cz>
Cc: "Randy Dunlap" <rdunlap@xenotime.net>,
	"Bruno Prémont" <bonbons@linux-vserver.org>,
	"Stephane Chatty" <chatty@enac.fr>,
	"Don Prince" <dhprince-devel@yahoo.co.uk>,
	"Dmitry Torokhov" <dtor@mail.ru>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org
Subject: [PATCH] HID: roccat: Using bin-attribute->private to reduce code duplication
Date: Fri, 05 Nov 2010 18:53:59 +0100	[thread overview]
Message-ID: <1288979639.2585.17.camel@neuromancer> (raw)
In-Reply-To: <alpine.LNX.2.00.1011041418530.15851@pobox.suse.cz>

The profile number is now passed via bin-attribute->private instead
of function parameter to reduce number of functions.

Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net>
---
 drivers/hid/hid-roccat-koneplus.c |  120 ++++++++-----------------------------
 1 files changed, 26 insertions(+), 94 deletions(-)

diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c
index 780acb4..7327e1a 100644
--- a/drivers/hid/hid-roccat-koneplus.c
+++ b/drivers/hid/hid-roccat-koneplus.c
@@ -26,6 +26,8 @@
 #include "hid-roccat.h"
 #include "hid-roccat-koneplus.h"
 
+static uint profile_numbers[5] = {0, 1, 2, 3, 4};
+
 static void koneplus_profile_activated(struct koneplus_device *koneplus,
 		uint new_profile)
 {
@@ -328,7 +330,7 @@ static ssize_t koneplus_sysfs_read_tcu_image(struct file *fp,
 
 static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp,
 		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count, uint number)
+		loff_t off, size_t count)
 {
 	struct device *dev = container_of(kobj, struct device, kobj);
 	struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
@@ -340,53 +342,13 @@ static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp,
 		count = sizeof(struct koneplus_profile_settings) - off;
 
 	mutex_lock(&koneplus->koneplus_lock);
-	memcpy(buf, ((void const *)&koneplus->profile_settings[number]) + off,
+	memcpy(buf, ((void const *)&koneplus->profile_settings[*(uint *)(attr->private)]) + off,
 			count);
 	mutex_unlock(&koneplus->koneplus_lock);
 
 	return count;
 }
 
-static ssize_t koneplus_sysfs_read_profile1_settings(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_settings(fp, kobj,
-			attr, buf, off, count, 0);
-}
-
-static ssize_t koneplus_sysfs_read_profile2_settings(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_settings(fp, kobj,
-			attr, buf, off, count, 1);
-}
-
-static ssize_t koneplus_sysfs_read_profile3_settings(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_settings(fp, kobj,
-			attr, buf, off, count, 2);
-}
-
-static ssize_t koneplus_sysfs_read_profile4_settings(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_settings(fp, kobj,
-			attr, buf, off, count, 3);
-}
-
-static ssize_t koneplus_sysfs_read_profile5_settings(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_settings(fp, kobj,
-			attr, buf, off, count, 4);
-}
-
 static ssize_t koneplus_sysfs_write_profile_settings(struct file *fp,
 		struct kobject *kobj, struct bin_attribute *attr, char *buf,
 		loff_t off, size_t count)
@@ -425,7 +387,7 @@ static ssize_t koneplus_sysfs_write_profile_settings(struct file *fp,
 
 static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp,
 		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count, uint number)
+		loff_t off, size_t count)
 {
 	struct device *dev = container_of(kobj, struct device, kobj);
 	struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev));
@@ -437,53 +399,13 @@ static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp,
 		count = sizeof(struct koneplus_profile_buttons) - off;
 
 	mutex_lock(&koneplus->koneplus_lock);
-	memcpy(buf, ((void const *)&koneplus->profile_buttons[number]) + off,
+	memcpy(buf, ((void const *)&koneplus->profile_buttons[*(uint *)(attr->private)]) + off,
 			count);
 	mutex_unlock(&koneplus->koneplus_lock);
 
 	return count;
 }
 
-static ssize_t koneplus_sysfs_read_profile1_buttons(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_buttons(fp, kobj,
-			attr, buf, off, count, 0);
-}
-
-static ssize_t koneplus_sysfs_read_profile2_buttons(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_buttons(fp, kobj,
-			attr, buf, off, count, 1);
-}
-
-static ssize_t koneplus_sysfs_read_profile3_buttons(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_buttons(fp, kobj,
-			attr, buf, off, count, 2);
-}
-
-static ssize_t koneplus_sysfs_read_profile4_buttons(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_buttons(fp, kobj,
-			attr, buf, off, count, 3);
-}
-
-static ssize_t koneplus_sysfs_read_profile5_buttons(struct file *fp,
-		struct kobject *kobj, struct bin_attribute *attr, char *buf,
-		loff_t off, size_t count)
-{
-	return koneplus_sysfs_read_profilex_buttons(fp, kobj,
-			attr, buf, off, count, 4);
-}
-
 static ssize_t koneplus_sysfs_write_profile_buttons(struct file *fp,
 		struct kobject *kobj, struct bin_attribute *attr, char *buf,
 		loff_t off, size_t count)
@@ -611,31 +533,36 @@ static struct bin_attribute koneplus_profile_settings_attr = {
 static struct bin_attribute koneplus_profile1_settings_attr = {
 		.attr = { .name = "profile1_settings", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_settings),
-		.read = koneplus_sysfs_read_profile1_settings
+		.read = koneplus_sysfs_read_profilex_settings,
+		.private = &profile_numbers[0]
 };
 
 static struct bin_attribute koneplus_profile2_settings_attr = {
 		.attr = { .name = "profile2_settings", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_settings),
-		.read = koneplus_sysfs_read_profile2_settings
+		.read = koneplus_sysfs_read_profilex_settings,
+		.private = &profile_numbers[1]
 };
 
 static struct bin_attribute koneplus_profile3_settings_attr = {
 		.attr = { .name = "profile3_settings", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_settings),
-		.read = koneplus_sysfs_read_profile3_settings
+		.read = koneplus_sysfs_read_profilex_settings,
+		.private = &profile_numbers[2]
 };
 
 static struct bin_attribute koneplus_profile4_settings_attr = {
 		.attr = { .name = "profile4_settings", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_settings),
-		.read = koneplus_sysfs_read_profile4_settings
+		.read = koneplus_sysfs_read_profilex_settings,
+		.private = &profile_numbers[3]
 };
 
 static struct bin_attribute koneplus_profile5_settings_attr = {
 		.attr = { .name = "profile5_settings", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_settings),
-		.read = koneplus_sysfs_read_profile5_settings
+		.read = koneplus_sysfs_read_profilex_settings,
+		.private = &profile_numbers[4]
 };
 
 static struct bin_attribute koneplus_profile_buttons_attr = {
@@ -647,31 +574,36 @@ static struct bin_attribute koneplus_profile_buttons_attr = {
 static struct bin_attribute koneplus_profile1_buttons_attr = {
 		.attr = { .name = "profile1_buttons", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_buttons),
-		.read = koneplus_sysfs_read_profile1_buttons
+		.read = koneplus_sysfs_read_profilex_buttons,
+		.private = &profile_numbers[0]
 };
 
 static struct bin_attribute koneplus_profile2_buttons_attr = {
 		.attr = { .name = "profile2_buttons", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_buttons),
-		.read = koneplus_sysfs_read_profile2_buttons
+		.read = koneplus_sysfs_read_profilex_buttons,
+		.private = &profile_numbers[1]
 };
 
 static struct bin_attribute koneplus_profile3_buttons_attr = {
 		.attr = { .name = "profile3_buttons", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_buttons),
-		.read = koneplus_sysfs_read_profile3_buttons
+		.read = koneplus_sysfs_read_profilex_buttons,
+		.private = &profile_numbers[2]
 };
 
 static struct bin_attribute koneplus_profile4_buttons_attr = {
 		.attr = { .name = "profile4_buttons", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_buttons),
-		.read = koneplus_sysfs_read_profile4_buttons
+		.read = koneplus_sysfs_read_profilex_buttons,
+		.private = &profile_numbers[3]
 };
 
 static struct bin_attribute koneplus_profile5_buttons_attr = {
 		.attr = { .name = "profile5_buttons", .mode = 0440 },
 		.size = sizeof(struct koneplus_profile_buttons),
-		.read = koneplus_sysfs_read_profile5_buttons
+		.read = koneplus_sysfs_read_profilex_buttons,
+		.private = &profile_numbers[4]
 };
 
 static struct bin_attribute koneplus_macro_attr = {
-- 
1.7.2.3




  parent reply	other threads:[~2010-11-05 17:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1287943025.2623.16.camel@neuromancer>
2010-11-04 18:25 ` [PATCH] HID: roccat: Add support for Roccat Kone[+] Jiri Kosina
2010-11-05 17:42   ` Stefan Achatz
2010-11-05 18:01     ` Jiri Kosina
2010-11-06 18:51       ` [PATCH 1/3] HID: roccat: Reducing number of functions in kone and pyra drivers Stefan Achatz
2010-11-06 18:52       ` [PATCH 2/3] HID: roccat: declaring meaning of pack pragma usage in koneplus driver Stefan Achatz
2010-11-06 18:53       ` [PATCH 3/3] HID: roccat: declaring meaning of pack pragma usage in kone and pyra driver Stefan Achatz
2010-11-12 19:16       ` [PATCH] HID: roccat: Add support for Roccat Kone[+] Stefan Achatz
2010-11-05 17:53   ` Stefan Achatz [this message]
2010-11-11  9:00 ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1288979639.2585.17.camel@neuromancer \
    --to=erazor_de@users.sourceforge.net \
    --cc=bonbons@linux-vserver.org \
    --cc=chatty@enac.fr \
    --cc=dhprince-devel@yahoo.co.uk \
    --cc=dtor@mail.ru \
    --cc=jkosina@suse.cz \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).