diff mbox

[01/11] HID: hid-input factorize hid_input allocation

Message ID 1353684694-5723-2-git-send-email-benjamin.tissoires@gmail.com (mailing list archive)
State New, archived
Delegated to: Jiri Kosina
Headers show

Commit Message

Benjamin Tissoires Nov. 23, 2012, 3:31 p.m. UTC
This just refactors the allocation of hid_input.
No semantic changes.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
---
 drivers/hid/hid-input.c | 61 +++++++++++++++++++++++++++----------------------
 1 file changed, 34 insertions(+), 27 deletions(-)

Comments

Henrik Rydberg Nov. 27, 2012, 7:45 p.m. UTC | #1
Hi Benjamin,

On Fri, Nov 23, 2012 at 04:31:24PM +0100, Benjamin Tissoires wrote:
> This just refactors the allocation of hid_input.

I think "breaks out the allocation" would be a more appropriate description.

> No semantic changes.
> 
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
> ---
>  drivers/hid/hid-input.c | 61 +++++++++++++++++++++++++++----------------------
>  1 file changed, 34 insertions(+), 27 deletions(-)

    Reviewed-by: Henrik Rydberg <rydberg@euromail.se>

Thanks,
Henrik
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiri Kosina Nov. 27, 2012, 7:47 p.m. UTC | #2
On Fri, 23 Nov 2012, Benjamin Tissoires wrote:

> This just refactors the allocation of hid_input.
> No semantic changes.
> 
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>

Fine by me, thanks.

> ---
>  drivers/hid/hid-input.c | 61 +++++++++++++++++++++++++++----------------------
>  1 file changed, 34 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> index 7015080..47f98a3 100644
> --- a/drivers/hid/hid-input.c
> +++ b/drivers/hid/hid-input.c
> @@ -1163,6 +1163,38 @@ static void report_features(struct hid_device *hid)
>  			}
>  }
>  
> +static struct hid_input *hidinput_allocate(struct hid_device *hid)
> +{
> +	struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL);
> +	struct input_dev *input_dev = input_allocate_device();
> +	if (!hidinput || !input_dev) {
> +		kfree(hidinput);
> +		input_free_device(input_dev);
> +		hid_err(hid, "Out of memory during hid input probe\n");
> +		return NULL;
> +	}
> +
> +	input_set_drvdata(input_dev, hid);
> +	input_dev->event = hid->ll_driver->hidinput_input_event;
> +	input_dev->open = hidinput_open;
> +	input_dev->close = hidinput_close;
> +	input_dev->setkeycode = hidinput_setkeycode;
> +	input_dev->getkeycode = hidinput_getkeycode;
> +
> +	input_dev->name = hid->name;
> +	input_dev->phys = hid->phys;
> +	input_dev->uniq = hid->uniq;
> +	input_dev->id.bustype = hid->bus;
> +	input_dev->id.vendor  = hid->vendor;
> +	input_dev->id.product = hid->product;
> +	input_dev->id.version = hid->version;
> +	input_dev->dev.parent = hid->dev.parent;
> +	hidinput->input = input_dev;
> +	list_add_tail(&hidinput->list, &hid->inputs);
> +
> +	return hidinput;
> +}
> +
>  /*
>   * Register the input device; print a message.
>   * Configure the input layer interface
> @@ -1174,7 +1206,6 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
>  	struct hid_driver *drv = hid->driver;
>  	struct hid_report *report;
>  	struct hid_input *hidinput = NULL;
> -	struct input_dev *input_dev;
>  	int i, j, k;
>  
>  	INIT_LIST_HEAD(&hid->inputs);
> @@ -1205,33 +1236,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force)
>  				continue;
>  
>  			if (!hidinput) {
> -				hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL);
> -				input_dev = input_allocate_device();
> -				if (!hidinput || !input_dev) {
> -					kfree(hidinput);
> -					input_free_device(input_dev);
> -					hid_err(hid, "Out of memory during hid input probe\n");
> +				hidinput = hidinput_allocate(hid);
> +				if (!hidinput)
>  					goto out_unwind;
> -				}
> -
> -				input_set_drvdata(input_dev, hid);
> -				input_dev->event =
> -					hid->ll_driver->hidinput_input_event;
> -				input_dev->open = hidinput_open;
> -				input_dev->close = hidinput_close;
> -				input_dev->setkeycode = hidinput_setkeycode;
> -				input_dev->getkeycode = hidinput_getkeycode;
> -
> -				input_dev->name = hid->name;
> -				input_dev->phys = hid->phys;
> -				input_dev->uniq = hid->uniq;
> -				input_dev->id.bustype = hid->bus;
> -				input_dev->id.vendor  = hid->vendor;
> -				input_dev->id.product = hid->product;
> -				input_dev->id.version = hid->version;
> -				input_dev->dev.parent = hid->dev.parent;
> -				hidinput->input = input_dev;
> -				list_add_tail(&hidinput->list, &hid->inputs);
>  			}
>  
>  			for (i = 0; i < report->maxfield; i++)
> -- 
> 1.8.0
>
Jiri Kosina Nov. 29, 2012, 2 p.m. UTC | #3
On Fri, 23 Nov 2012, Benjamin Tissoires wrote:

> This just refactors the allocation of hid_input.
> No semantic changes.

As this is a generic cleanup, I am taking this one through 
for-3.8/upstream branch.

Thanks,
Benjamin Tissoires Nov. 29, 2012, 2:58 p.m. UTC | #4
On Thu, Nov 29, 2012 at 3:00 PM, Jiri Kosina <jkosina@suse.cz> wrote:
> On Fri, 23 Nov 2012, Benjamin Tissoires wrote:
>
>> This just refactors the allocation of hid_input.
>> No semantic changes.
>
> As this is a generic cleanup, I am taking this one through
> for-3.8/upstream branch.

Thanks Jiri.
Sorry for not answering earlier, I was working on an other solution
for pen devices before speculating on the review of the other patches
:)

Cheers,
Benjamin

>
> Thanks,
>
> --
> Jiri Kosina
> SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 7015080..47f98a3 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1163,6 +1163,38 @@  static void report_features(struct hid_device *hid)
 			}
 }
 
+static struct hid_input *hidinput_allocate(struct hid_device *hid)
+{
+	struct hid_input *hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL);
+	struct input_dev *input_dev = input_allocate_device();
+	if (!hidinput || !input_dev) {
+		kfree(hidinput);
+		input_free_device(input_dev);
+		hid_err(hid, "Out of memory during hid input probe\n");
+		return NULL;
+	}
+
+	input_set_drvdata(input_dev, hid);
+	input_dev->event = hid->ll_driver->hidinput_input_event;
+	input_dev->open = hidinput_open;
+	input_dev->close = hidinput_close;
+	input_dev->setkeycode = hidinput_setkeycode;
+	input_dev->getkeycode = hidinput_getkeycode;
+
+	input_dev->name = hid->name;
+	input_dev->phys = hid->phys;
+	input_dev->uniq = hid->uniq;
+	input_dev->id.bustype = hid->bus;
+	input_dev->id.vendor  = hid->vendor;
+	input_dev->id.product = hid->product;
+	input_dev->id.version = hid->version;
+	input_dev->dev.parent = hid->dev.parent;
+	hidinput->input = input_dev;
+	list_add_tail(&hidinput->list, &hid->inputs);
+
+	return hidinput;
+}
+
 /*
  * Register the input device; print a message.
  * Configure the input layer interface
@@ -1174,7 +1206,6 @@  int hidinput_connect(struct hid_device *hid, unsigned int force)
 	struct hid_driver *drv = hid->driver;
 	struct hid_report *report;
 	struct hid_input *hidinput = NULL;
-	struct input_dev *input_dev;
 	int i, j, k;
 
 	INIT_LIST_HEAD(&hid->inputs);
@@ -1205,33 +1236,9 @@  int hidinput_connect(struct hid_device *hid, unsigned int force)
 				continue;
 
 			if (!hidinput) {
-				hidinput = kzalloc(sizeof(*hidinput), GFP_KERNEL);
-				input_dev = input_allocate_device();
-				if (!hidinput || !input_dev) {
-					kfree(hidinput);
-					input_free_device(input_dev);
-					hid_err(hid, "Out of memory during hid input probe\n");
+				hidinput = hidinput_allocate(hid);
+				if (!hidinput)
 					goto out_unwind;
-				}
-
-				input_set_drvdata(input_dev, hid);
-				input_dev->event =
-					hid->ll_driver->hidinput_input_event;
-				input_dev->open = hidinput_open;
-				input_dev->close = hidinput_close;
-				input_dev->setkeycode = hidinput_setkeycode;
-				input_dev->getkeycode = hidinput_getkeycode;
-
-				input_dev->name = hid->name;
-				input_dev->phys = hid->phys;
-				input_dev->uniq = hid->uniq;
-				input_dev->id.bustype = hid->bus;
-				input_dev->id.vendor  = hid->vendor;
-				input_dev->id.product = hid->product;
-				input_dev->id.version = hid->version;
-				input_dev->dev.parent = hid->dev.parent;
-				hidinput->input = input_dev;
-				list_add_tail(&hidinput->list, &hid->inputs);
 			}
 
 			for (i = 0; i < report->maxfield; i++)