HID: Fine-tuning for several function implementations
Subsystems (3)
cover HID: Fine-tuning for several function implementations
From: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:26:54 +0100
Several update suggestions were taken into account from static source code analysis.
Markus Elfring (18):
Use kmalloc_array() in hid_input_field()
Delete an error message for a failed memory allocation in open_collection() Use kmalloc_array() in open_collection()
Improve another size determination in open_collection()
Improve two size determinations in hid_open_report()
Improve another size determination in hid_scan_report()
Improve another size determination in hid_register_report() Adjust five checks for null pointers
Return an error code only as a constant in hid_allocate_device()
debug: Replace five seq_printf() calls by seq_putc()
debug: Delete an unnecessary seq_printf() call in hid_dump_device()
debug: Replace 12 seq_printf() calls by seq_puts()
debug: Combine 11 seq_printf() calls into one call in hid_dump_field()
debug: Adjust two function calls together with a variable assignment
debug: Return an error code only as a constant in hid_debug_events_open()
debug: Add some spaces for better code readability
debug: Delete an unnecessary variable initialisation in hid_resolv_usage() Use seq_puts() in picolcd_debug_reset_show()
drivers/hid/hid-core.c | 39 ++++++------- drivers/hid/hid-debug.c | 115 +++++++++++++++++++------------------- drivers/hid/hid-picolcd_debugfs.c | 6 +- 3 files changed, 78 insertions(+), 82 deletions(-)
Signature · 1 line
2.11.1
PATCH 1/18 HID: Use kmalloc_array() in hid_input_field()
From: Markus Elfring <[email protected]>
Date: Mon, 6 Feb 2017 18:18:41 +0100
A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
This issue was detected by using the Coccinelle software.
--- drivers/hid/hid-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-core.c +1 -1
@@ -1272,7 +1272,7 @@ static void hid_input_field(struct hid_device *hid, struct hid_field *field,__s32 max = field->logical_maximum;__s32 *value; - value =kmalloc (sizeof (__s32) * count,GFP_ATOMIC ); + value =kmalloc_array (count,sizeof (__s32),GFP_ATOMIC );if (!value)return ;
Signature · 1 line
2.11.1
PATCH 2/18 HID: Delete an error message for a failed memory allocation in open_collection()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 6 Feb 2017 18:42:26 +0100
The script "checkpatch.pl" pointed information out like the following.
WARNING: Possible unnecessary 'out of memory' message
Thus fix the affected source code place.
--- drivers/hid/hid-core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/hid/hid-core.c +2 -3
@@ -133,10 +133,9 @@ static int open_collection(struct hid_parser *parser, unsigned type)if (parser->device->maxcollection = parser->device->collection_size) { collection =kmalloc (sizeof (struct hid_collection ) * parser->device->collection_size *2 ,GFP_KERNEL ); -if (collection =NULL ) { -hid_err (parser->device,"failed to reallocate collection array\n" ); +if (!collection)return -ENOMEM ; - } +memcpy (collection, parser->device->collection,sizeof (struct hid_collection ) * parser->device->collection_size);
Signature · 1 line
2.11.1
PATCH 3/18 HID: Use kmalloc_array() in open_collection()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 6 Feb 2017 19:09:42 +0100
* A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array".
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/hid/hid-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +3 -2
@@ -131,8 +131,9 @@ static int open_collection(struct hid_parser *parser, unsigned type) }if (parser->device->maxcollection = parser->device->collection_size) { - collection =kmalloc (sizeof (struct hid_collection ) * - parser->device->collection_size *2 ,GFP_KERNEL ); + collection =kmalloc_array (parser->device->collection_size *2 , +sizeof (*collection), +GFP_KERNEL );if (!collection)return -ENOMEM ;
Signature · 1 line
2.11.1
PATCH 4/18 HID: Improve another size determination in open_collection()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 6 Feb 2017 19:19:22 +0100
Replace the specification of a data structure by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/hid/hid-core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hid/hid-core.c +2 -4
@@ -138,11 +138,9 @@ static int open_collection(struct hid_parser *parser, unsigned type)return -ENOMEM ;memcpy (collection, parser->device->collection, -sizeof (struct hid_collection ) * - parser->device->collection_size); +sizeof (*collection) * parser->device->collection_size);memset (collection + parser->device->collection_size,0 , -sizeof (struct hid_collection ) * - parser->device->collection_size); +sizeof (*collection) * parser->device->collection_size);kfree (parser->device->collection); parser->device->collection = collection; parser->device->collection_size *=2 ;
Signature · 1 line
2.11.1
PATCH 5/18 HID: Improve two size determinations in hid_open_report()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 6 Feb 2017 22:00:07 +0100
Replace the specification of data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/hid/hid-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-core.c +2 -2
@@ -975,7 +975,7 @@ int hid_open_report(struct hid_device *device) device->rdesc = start; device->rsize = size; - parser =vzalloc (sizeof (struct hid_parser )); + parser =vzalloc (sizeof (*parser));if (!parser) { ret = -ENOMEM ; goto err;
@@ -986,7 +986,7 @@ int hid_open_report(struct hid_device *device) end = start + size; device->collection =kcalloc (HID_DEFAULT_NUM_COLLECTIONS , -sizeof (struct hid_collection ),GFP_KERNEL ); +sizeof (*device->collection),GFP_KERNEL );if (!device->collection) { ret = -ENOMEM ; goto err;
Signature · 1 line
2.11.1
PATCH 6/18 HID: Improve another size determination in hid_scan_report()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 19:10:53 +0100
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/hid/hid-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-core.c +1 -1
@@ -787,7 +787,7 @@ static int hid_scan_report(struct hid_device *hid) hid_parser_reserved }; - parser =vzalloc (sizeof (struct hid_parser )); + parser =vzalloc (sizeof (*parser));if (!parser)return -ENOMEM ;
Signature · 1 line
2.11.1
PATCH 7/18 HID: Improve another size determination in hid_register_report()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 19:12:56 +0100
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/hid/hid-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-core.c +1 -1
@@ -67,7 +67,7 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,if (report_enum->report_id_hash[id])return report_enum->report_id_hash[id]; - report =kzalloc (sizeof (struct hid_report ),GFP_KERNEL ); + report =kzalloc (sizeof (*report),GFP_KERNEL );if (!report)return NULL ;
Signature · 1 line
2.11.1
PATCH 8/18 HID: Adjust five checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 19:15:21 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The script "checkpatch.pl" pointed information out like the following.
Comparison to NULL could be written !…
Thus fix affected source code places.
--- drivers/hid/hid-core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/hid/hid-core.c +5 -5
@@ -959,7 +959,7 @@ int hid_open_report(struct hid_device *device) size = device->dev_rsize; buf =kmemdup (start, size,GFP_KERNEL ); -if (buf =NULL ) +if (!buf)return -ENOMEM ;if (device->driver->report_fixup)
@@ -969,7 +969,7 @@ int hid_open_report(struct hid_device *device) start =kmemdup (start, size,GFP_KERNEL );kfree (buf); -if (start =NULL ) +if (!start)return -ENOMEM ; device->rdesc = start;
@@ -1414,7 +1414,7 @@ static struct hid_report *hid_get_report(struct hid_report_enum *report_enum, n = *data; report = report_enum->report_id_hash[n]; -if (report =NULL ) +if (!report)dbg_hid ("undefined report_id %u received\n" , n);return report;
@@ -2222,7 +2222,7 @@ static int hid_device_probe(struct device *dev)if (!hdev->driver) { id =hid_match_device (hdev, hdrv); -if (id =NULL ) { +if (!id) { ret = -ENODEV ; goto unlock; }
@@ -2719,7 +2719,7 @@ struct hid_device *hid_allocate_device(void)int ret = -ENOMEM ; hdev =kzalloc (sizeof (*hdev),GFP_KERNEL ); -if (hdev =NULL ) +if (!hdev)return ERR_PTR (ret);device_initialize (&hdev->dev);
Signature · 6 lines
2.11.1 -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 9/18 HID: Return an error code only as a constant in hid_allocate_device()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 19:17:36 +0100
* Return an error code without storing it in an intermediate variable.
* Delete the local variable "ret" which became unnecessary with this refactoring.
--- drivers/hid/hid-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hid/hid-core.c +1 -2
@@ -2716,11 +2716,10 @@ EXPORT_SYMBOL_GPL(hid_add_device);struct hid_device *hid_allocate_device (void ) {struct hid_device *hdev; -int ret = -ENOMEM ; hdev =kzalloc (sizeof (*hdev),GFP_KERNEL );if (!hdev) -return ERR_PTR (ret); +return ERR_PTR (-ENOMEM );device_initialize (&hdev->dev); hdev->dev.release = hid_device_release;
Signature · 1 line
2.11.1
PATCH 10/18 HID-debug: Replace five seq_printf() calls by seq_putc()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 19:21:17 +0100
Single characters should be put into a sequence.
Thus use the corresponding function "seq_putc".
This issue was detected by using the Coccinelle software.
--- drivers/hid/hid-debug.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/hid/hid-debug.c +7 -5
@@ -497,7 +497,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) { len++; }else { -seq_printf (f,"." ); +seq_putc (f,'.' ); }for (p = hid_usage_table; p->description; p++)if (p->page = (usage >>16 )) {
@@ -548,7 +548,9 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) { }tab (n, f);seq_printf (f,"Usage(%d)\n" , field->maxusage);for (j =0 ; j < field->maxusage; j++) { -tab (n+2 , f);hid_resolv_usage (field->usage[j].hid, f);seq_printf (f,"\n" ); +tab (n +2 , f); +hid_resolv_usage (field->usage[j].hid, f); +seq_putc (f,'\n' ); }if (field->logical_minimum != field->logical_maximum) {tab (n, f);seq_printf (f,"Logical Minimum(%d)\n" , field->logical_minimum);
@@ -592,7 +594,7 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) { data >>=4 ;if (nibble !=0 ) {if (earlier_unit++ >0 ) -seq_printf (f,"*" ); +seq_putc (f,'*' );seq_printf (f,"%s" , units[sys][i]);if (nibble !=1 ) {/* This is a _signed_ nibble(!) */
@@ -1037,7 +1039,7 @@ static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)hid_resolv_usage (usage->hid, f);seq_printf (f," ---> " );hid_resolv_event (usage->type, usage->code, f); -seq_printf (f,"\n" ); +seq_putc (f,'\n' ); } } }
@@ -1064,7 +1066,7 @@ static int hid_debug_rdesc_show(struct seq_file *f, void *p)/* dump parsed data and input mappings */ hid_dump_device (hdev, f); -seq_printf (f,"\n" ); +seq_putc (f,'\n' );hid_dump_input_mapping (hdev, f);return 0 ;
Signature · 1 line
2.11.1
PATCH 11/18 HID-debug: Delete an unnecessary seq_printf() call in hid_dump_device()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 19:23:03 +0100
An information should be put into a sequence together with a line break. Pass the desired data in a single function call instead.
--- drivers/hid/hid-debug.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/hid/hid-debug.c +1 -2
@@ -645,8 +645,7 @@ void hid_dump_device(struct hid_device *device, struct seq_file *f)seq_printf (f,"%s" , table[i]);if (report->id)seq_printf (f,"(%d)" , report->id); -seq_printf (f,"[%s]" , table[report->type]); -seq_printf (f,"\n" ); +seq_printf (f,"[%s]\n" , table[report->type]);for (k =0 ; k < report->maxfield; k++) {tab (4 , f);seq_printf (f,"Field(%d)\n" , k);
Signature · 1 line
2.11.1
PATCH 12/18 HID-debug: Replace 12 seq_printf() calls by seq_puts()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:02:45 +0100
Strings which did not contain data format specifications should be put into a sequence. Thus use the corresponding function "seq_puts".
This issue was detected by using the Coccinelle software.
--- drivers/hid/hid-debug.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/hid/hid-debug.c +16 -14
@@ -508,9 +508,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) {max (0 ,HID_DEBUG_BUFSIZE - len -1 ), "%s", p->description); else - seq_printf(f, -"%s" , - p->description); + seq_puts(f, p->description);return buf; }break ;
@@ -533,18 +531,21 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {if (field->physical) {tab (n, f); -seq_printf (f,"Physical(" ); -hid_resolv_usage (field->physical, f);seq_printf (f,")\n" ); +seq_puts (f,"Physical(" ); +hid_resolv_usage (field->physical, f); +seq_puts (f,")\n" ); }if (field->logical) {tab (n, f); -seq_printf (f,"Logical(" ); -hid_resolv_usage (field->logical, f);seq_printf (f,")\n" ); +seq_puts (f,"Logical(" ); +hid_resolv_usage (field->logical, f); +seq_puts (f,")\n" ); }if (field->application) {tab (n, f); -seq_printf (f,"Application(" ); -hid_resolv_usage (field->application, f);seq_printf (f,")\n" ); +seq_puts (f,"Application(" ); +hid_resolv_usage (field->application, f); +seq_puts (f,")\n" ); }tab (n, f);seq_printf (f,"Usage(%d)\n" , field->maxusage);for (j =0 ; j < field->maxusage; j++) {
@@ -582,7 +583,8 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) { data >>=4 ;if (sys >4 ) { -tab (n, f);seq_printf (f,"Unit(Invalid)\n" ); +tab (n, f); +seq_puts (f,"Unit(Invalid)\n" ); }else {int earlier_unit =0 ;
@@ -595,7 +597,7 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {if (nibble !=0 ) {if (earlier_unit++ >0 )seq_putc (f,'*' ); -seq_printf (f,"%s" , units[sys][i]); +seq_puts (f, units[sys][i]);if (nibble !=1 ) {/* This is a _signed_ nibble(!) */
@@ -606,7 +608,7 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) { } } } -seq_printf (f,")\n" ); +seq_puts (f,")\n" ); } }tab (n, f);seq_printf (f,"Report Size(%u)\n" , field->report_size);
@@ -1036,7 +1038,7 @@ static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)for ( j =0 ; j < report->field[i]->maxusage; j++) { usage = report->field[i]->usage + j;hid_resolv_usage (usage->hid, f); -seq_printf (f," ---> " ); +seq_puts (f," ---> " );hid_resolv_event (usage->type, usage->code, f);seq_putc (f,'\n' ); }
@@ -1061,7 +1063,7 @@ static int hid_debug_rdesc_show(struct seq_file *f, void *p)/* dump HID report descriptor */ for (i =0 ; i < rsize; i++)seq_printf (f,"%02x " , rdesc[i]); -seq_printf (f,"\n\n" ); +seq_puts (f,"\n\n" );/* dump parsed data and input mappings */ hid_dump_device (hdev, f);
Signature · 1 line
2.11.1
PATCH 13/18 HID-debug: Combine 11 seq_printf() calls into one call in hid_dump_field()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:04:28 +0100
Some data were printed into a sequence by eleven separate function calls. Print the same data by a single function call instead.
--- drivers/hid/hid-debug.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/hid/hid-debug.c +11 -12
@@ -614,19 +614,18 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {tab (n, f);seq_printf (f,"Report Size(%u)\n" , field->report_size);tab (n, f);seq_printf (f,"Report Count(%u)\n" , field->report_count);tab (n, f);seq_printf (f,"Report Offset(%u)\n" , field->report_offset); - -tab (n, f);seq_printf (f,"Flags( " ); +tab (n, f); j = field->flags; -seq_printf (f,"%s" ,HID_MAIN_ITEM_CONSTANT & j ?"Constant " :"" ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_VARIABLE & j ?"Variable " :"Array " ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_RELATIVE & j ?"Relative " :"Absolute " ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_WRAP & j ?"Wrap " :"" ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_NONLINEAR & j ?"NonLinear " :"" ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_NO_PREFERRED & j ?"NoPreferredState " :"" ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_NULL_STATE & j ?"NullState " :"" ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_VOLATILE & j ?"Volatile " :"" ); -seq_printf (f,"%s" ,HID_MAIN_ITEM_BUFFERED_BYTE & j ?"BufferedByte " :"" ); -seq_printf (f,")\n" ); +seq_printf (f,"Flags( %s%s%s%s%s%s%s%s%s)\n" , +HID_MAIN_ITEM_CONSTANT & j ?"Constant " :"" , +HID_MAIN_ITEM_VARIABLE & j ?"Variable " :"Array " , +HID_MAIN_ITEM_RELATIVE & j ?"Relative " :"Absolute " , +HID_MAIN_ITEM_WRAP & j ?"Wrap " :"" , +HID_MAIN_ITEM_NONLINEAR & j ?"NonLinear " :"" , +HID_MAIN_ITEM_NO_PREFERRED & j ?"NoPreferredState " :"" , +HID_MAIN_ITEM_NULL_STATE & j ?"NullState " :"" , +HID_MAIN_ITEM_VOLATILE & j ?"Volatile " :"" , +HID_MAIN_ITEM_BUFFERED_BYTE & j ?"BufferedByte " :"" ); }EXPORT_SYMBOL_GPL (hid_dump_field);
Signature · 1 line
2.11.1
Re: [PATCH 13/18] HID-debug: Combine 11 seq_printf() calls into one call in hid_dump_field()
drivers/hid/hid-debug.c
Quoted 1 line · SF Markus Elfring
drivers/hid/hid-debug.c +0
-0
[]
drivers/hid/hid-debug.c void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) { · line 617
Quoted 7 lines
drivers/hid/hid-debug.c +1
-2@@ -614,19 +614,18 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {tab (n, f);seq_printf (f,"Report Size(%u)\n" , field->report_size);tab (n, f);seq_printf (f,"Report Count(%u)\n" , field->report_count);tab (n, f);seq_printf (f,"Report Offset(%u)\n" , field->report_offset); - -tab (n, f);seq_printf (f,"Flags( " ); +tab (n, f);
Consider converting tab(n, f) to seq_indent(f, n) making seq_indent a global function or maybe using a new name like seq_spaces, and converting the existing uses in net/ipv4/fib_trie.c appropriately.
PATCH 14/18 HID-debug: Adjust two function calls together with a variable assignment
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:06:31 +0100
* The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix the affected source code places.
* Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- drivers/hid/hid-debug.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/hid/hid-debug.c +5 -2
@@ -1083,12 +1083,15 @@ static int hid_debug_events_open(struct inode *inode, struct file *file)struct hid_debug_list *list;unsigned long flags; -if (!(list =kzalloc (sizeof (struct hid_debug_list ),GFP_KERNEL ))) { + list =kzalloc (sizeof (*list),GFP_KERNEL ); +if (!list) { err = -ENOMEM ; goto out; } -if (!(list->hid_debug_buf =kzalloc (sizeof (char ) *HID_DEBUG_BUFSIZE ,GFP_KERNEL ))) { + list->hid_debug_buf =kzalloc (sizeof (char ) *HID_DEBUG_BUFSIZE , +GFP_KERNEL ); +if (!list->hid_debug_buf) { err = -ENOMEM ;kfree (list); goto out;
Signature · 1 line
2.11.1
PATCH 15/18 HID-debug: Return an error code only as a constant in hid_debug_events_open()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:08:04 +0100
* Return an error code without storing it in an intermediate variable.
* Delete the local variable "err" and the jump label "out" which became unnecessary with this refactoring.
--- drivers/hid/hid-debug.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/hid/hid-debug.c +4 -10
@@ -1079,22 +1079,18 @@ static int hid_debug_rdesc_open(struct inode *inode, struct file *file)static int hid_debug_events_open (struct inode *inode,struct file *file) { -int err =0 ;struct hid_debug_list *list;unsigned long flags; list =kzalloc (sizeof (*list),GFP_KERNEL ); -if (!list) { - err = -ENOMEM ; - goto out; - } +if (!list) +return -ENOMEM ; list->hid_debug_buf =kzalloc (sizeof (char ) *HID_DEBUG_BUFSIZE ,GFP_KERNEL );if (!list->hid_debug_buf) { - err = -ENOMEM ;kfree (list); - goto out; +return -ENOMEM ; } list->hdev = (struct hid_device *) inode->i_private; file->private_data = list;
@@ -1103,9 +1099,7 @@ static int hid_debug_events_open(struct inode *inode, struct file *file)spin_lock_irqsave (&list->hdev->debug_list_lock, flags);list_add_tail (&list->node, &list->hdev->debug_list);spin_unlock_irqrestore (&list->hdev->debug_list_lock, flags); - -out: -return err; +return 0 ; } static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
Signature · 1 line
2.11.1
PATCH 16/18 HID-debug: Add some spaces for better code readability
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:10:40 +0100
Use space characters at some source code places according to the Linux coding style convention.
--- drivers/hid/hid-debug.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/hid/hid-debug.c +14 -12
@@ -493,7 +493,7 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) {if (!f) { len =strlen (buf); -snprintf (buf+len,max (0 ,HID_DEBUG_BUFSIZE - len),"." ); +snprintf (buf + len,max (0 ,HID_DEBUG_BUFSIZE - len),"." ); len++; }else {
@@ -501,12 +501,14 @@ char *hid_resolv_usage(unsigned usage, struct seq_file *f) { }for (p = hid_usage_table; p->description; p++)if (p->page = (usage >>16 )) { -for (++p; p->description && p->usage !=0 ; p++) +for (++p; p->description && p->usage !=0 ; p++)if (p->usage = (usage &0xffff )) {if (!f)snprintf (buf + len, -max (0 ,HID_DEBUG_BUFSIZE - len -1 ), -"%s" , p->description); +max (0 , +HID_DEBUG_BUFSIZE + - len -1 ), +"%s" , p->description);else seq_puts (f, p->description);return buf;
@@ -582,7 +584,7 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) { sys = data &0xf ; data >>=4 ; -if (sys >4 ) { +if (sys >4 ) {tab (n, f);seq_puts (f,"Unit(Invalid)\n" ); }
@@ -591,19 +593,19 @@ void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {tab (n, f);seq_printf (f,"Unit(%s : " , systems[sys]); -for (i=1 ; i<sizeof (__u32)*2 ; i++) { +for (i =1 ; i <sizeof (__u32) *2 ; i++) {char nibble = data &0xf ; data >>=4 ;if (nibble !=0 ) { -if (earlier_unit++ >0 ) +if (earlier_unit++ >0 )seq_putc (f,'*' );seq_puts (f, units[sys][i]); -if (nibble !=1 ) { +if (nibble !=1 ) {/* This is a _signed_ nibble(!) */ -int val = nibble &0x7 ; -if (nibble &0x08 ) - val = -((0x7 & ~val) +1 ); + +if (nibble &0x08 ) + val = -((0x7 & ~val) +1 );seq_printf (f,"^%d" , val); } }
@@ -634,7 +636,7 @@ void hid_dump_device(struct hid_device *device, struct seq_file *f)struct hid_report_enum *report_enum;struct hid_report *report;struct list_head *list; -unsigned i,k; +unsigned int i, k;static const char *table[] = {"INPUT" ,"OUTPUT" ,"FEATURE" };for (i =0 ; i <HID_REPORT_TYPES ; i++) {
Signature · 1 line
2.11.1
PATCH 17/18 HID-debug: Delete an unnecessary variable initialisation in hid_resolv_usage()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:12:09 +0100
The local variable "buf" will be set to an appropriate pointer by the following statement. Thus omit the explicit initialisation at the beginning.
--- drivers/hid/hid-debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-debug.c +1 -1
@@ -481,7 +481,7 @@ static char *resolv_usage_page(unsigned page, struct seq_file *f) {char *hid_resolv_usage (unsigned usage,struct seq_file *f) {const struct hid_usage_entry *p; -char *buf =NULL ; +char *buf;int len =0 ; buf =resolv_usage_page (usage >>16 , f);
Signature · 1 line
2.11.1
PATCH 18/18 HID-picoLCD: Use seq_puts() in picolcd_debug_reset_show()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Tue, 7 Feb 2017 20:14:16 +0100
A string which did not contain a data format specification should be put into a sequence. Thus use the corresponding function "seq_puts".
This issue was detected by using the Coccinelle software.
--- drivers/hid/hid-picolcd_debugfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/hid/hid-picolcd_debugfs.c +2 -4
@@ -32,10 +32,8 @@static int picolcd_debug_reset_show (struct seq_file *f,void *p) { -if (picolcd_fbinfo ((struct picolcd_data *)f->private)) -seq_printf (f,"all fb\n" ); -else -seq_printf (f,"all\n" ); +seq_puts (f,picolcd_fbinfo ((struct picolcd_data *)f->private) + ?"all fb\n" :"all\n" );return 0 ; }
Signature · 1 line
2.11.1