HID: logitech-dj: Adjustments for some function implementations
Subsystems (3)
cover HID: logitech-dj: Adjustments for some function implementations
From: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2018 22:22:11 +0100
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (4):
Delete an error message for a failed memory allocation in two functions Improve a size determination in four functions
Combine substrings for seven messages
Fix a typo in a comment line
drivers/hid/hid-logitech-dj.c | 53 +++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 30 deletions(-)
Signature · 1 line
2.16.1
PATCH 1/4 HID: logitech-dj: Delete an error message for a failed memory allocation in two functions
From: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2018 21:36:18 +0100
Omit an extra message for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
--- drivers/hid/hid-logitech-dj.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/hid/hid-logitech-dj.c +3 -9
@@ -418,12 +418,8 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,strlcat (dj_hiddev->phys, tmpstr,sizeof (dj_hiddev->phys)); dj_dev =kzalloc (sizeof (struct dj_device ),GFP_KERNEL ); - -if (!dj_dev) { -dev_err (&djrcv_hdev->dev,"%s: failed allocating dj_device\n" , - __func__); +if (!dj_dev) goto dj_device_allocate_fail; - } dj_dev->reports_supported =get_unaligned_le32 ( dj_report->report_params +DEVICE_PAIRED_RF_REPORT_TYPE );
@@ -1011,11 +1007,9 @@ static int logi_dj_probe(struct hid_device *hdev,/* Treat interface 2 */ djrcv_dev =kzalloc (sizeof (struct dj_receiver_dev ),GFP_KERNEL ); -if (!djrcv_dev) { -dev_err (&hdev->dev, -"%s:failed allocating dj_receiver_dev\n" , __func__); +if (!djrcv_dev)return -ENOMEM ; - } + djrcv_dev->hdev = hdev;INIT_WORK (&djrcv_dev->work, delayedwork_callback);spin_lock_init (&djrcv_dev->lock);
Signature · 1 line
2.16.1
PATCH 2/4 HID: logitech-dj: Improve a size determination in four functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2018 21:47:45 +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.
This issue was detected by using the Coccinelle software.
--- drivers/hid/hid-logitech-dj.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/hid/hid-logitech-dj.c +4 -6
@@ -417,7 +417,7 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,snprintf (tmpstr,sizeof (tmpstr),":%d" , dj_report->device_index);strlcat (dj_hiddev->phys, tmpstr,sizeof (dj_hiddev->phys)); - dj_dev =kzalloc (sizeof (struct dj_device ),GFP_KERNEL ); + dj_dev =kzalloc (sizeof (*dj_dev),GFP_KERNEL );if (!dj_dev) goto dj_device_allocate_fail;
@@ -611,7 +611,7 @@ static int logi_dj_recv_query_paired_devices(struct dj_receiver_dev *djrcv_dev)if (djrcv_dev->querying_devices)return 0 ; - dj_report =kzalloc (sizeof (struct dj_report ),GFP_KERNEL ); + dj_report =kzalloc (sizeof (*dj_report),GFP_KERNEL );if (!dj_report)return -ENOMEM ; dj_report->report_id =REPORT_ID_DJ_SHORT ;
@@ -627,11 +627,10 @@ static int logi_dj_recv_switch_to_dj_mode(struct dj_receiver_dev *djrcv_dev, unsigned timeout) {struct hid_device *hdev = djrcv_dev->hdev; -struct dj_report *dj_report;u8 *buf;int retval; +struct dj_report *dj_report =kzalloc (sizeof (*dj_report),GFP_KERNEL ); - dj_report =kzalloc (sizeof (struct dj_report ),GFP_KERNEL );if (!dj_report)return -ENOMEM ; dj_report->report_id =REPORT_ID_DJ_SHORT ;
@@ -1005,8 +1004,7 @@ static int logi_dj_probe(struct hid_device *hdev, }/* Treat interface 2 */ - - djrcv_dev =kzalloc (sizeof (struct dj_receiver_dev ),GFP_KERNEL ); + djrcv_dev =kzalloc (sizeof (*djrcv_dev),GFP_KERNEL );if (!djrcv_dev)return -ENOMEM ;
Signature · 1 line
2.16.1
PATCH 3/4 HID: logitech-dj: Combine substrings for seven messages
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2018 22:06:20 +0100
The script "checkpatch.pl" pointed information out like the following.
WARNING: quoted string split across lines
Thus fix the affected source code places.
--- drivers/hid/hid-logitech-dj.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
drivers/hid/hid-logitech-dj.c +15 -14
@@ -463,16 +463,17 @@ static void delayedwork_callback(struct work_struct *work) sizeof(struct dj_report));if (count !=sizeof (struct dj_report )) { -dev_err (&djrcv_dev->hdev->dev,"%s: workitem triggered without " -"notifications available\n" , __func__); +dev_err (&djrcv_dev->hdev->dev, +"%s: workitem triggered without notifications available\n" , + __func__);spin_unlock_irqrestore (&djrcv_dev->lock, flags);return ; }if (!kfifo_is_empty (&djrcv_dev->notif_fifo)) {if (schedule_work (&djrcv_dev->work) =0 ) { -dbg_hid ("%s: did not schedule the work item, was " -"already queued\n" , __func__); +dbg_hid ("%s: did not schedule the work item, was already queued\n" , + __func__); } }
@@ -502,8 +503,8 @@ static void delayedwork_callback(struct work_struct *work)break ; }dev_err (&djrcv_dev->hdev->dev, -"%s:logi_dj_recv_query_paired_devices " -"error:%d\n" , __func__, retval); +"%s:logi_dj_recv_query_paired_devices error:%d\n" , + __func__, retval); }dbg_hid ("%s: unexpected report type\n" , __func__); }
@@ -517,8 +518,8 @@ static void logi_dj_recv_queue_notification(struct dj_receiver_dev *djrcv_dev,kfifo_in (&djrcv_dev->notif_fifo, dj_report,sizeof (struct dj_report ));if (schedule_work (&djrcv_dev->work) =0 ) { -dbg_hid ("%s: did not schedule the work item, was already " -"queued\n" , __func__); +dbg_hid ("%s: did not schedule the work item, was already queued\n" , + __func__); } }
@@ -541,8 +542,7 @@ static void logi_dj_recv_forward_null_report(struct dj_receiver_dev *djrcv_dev, HID_INPUT_REPORT, reportbuffer, hid_reportid_size_map[i], 1)) { -dbg_hid ("hid_input_report error sending null " -"report\n" ); +dbg_hid ("hid_input_report error sending null report\n" ); } } }
@@ -770,8 +770,8 @@ static int logi_dj_ll_parse(struct hid_device *hid) }if (djdev->reports_supported &STD_MOUSE ) { -dbg_hid ("%s: sending a mouse descriptor, reports_supported: " -"%x\n" , __func__, djdev->reports_supported); +dbg_hid ("%s: sending a mouse descriptor, reports_supported: %x\n" , + __func__, djdev->reports_supported);rdcat (rdesc, &rsize, mse_descriptor,sizeof (mse_descriptor)); }
@@ -1068,8 +1068,9 @@ static int logi_dj_probe(struct hid_device *hdev, retval =logi_dj_recv_query_paired_devices (djrcv_dev);if (retval <0 ) { -dev_err (&hdev->dev,"%s:logi_dj_recv_query_paired_devices " -"error:%d\n" , __func__, retval); +dev_err (&hdev->dev, +"%s:logi_dj_recv_query_paired_devices error:%d\n" , + __func__, retval); goto logi_dj_recv_query_paired_devices_failed; }
Signature · 1 line
2.16.1
PATCH 4/4 HID: logitech-dj: Fix a typo in a comment line
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 5 Feb 2018 22:14:49 +0100
Adjust a word in this description.
--- drivers/hid/hid-logitech-dj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-logitech-dj.c +1 -1
@@ -318,7 +318,7 @@ static const char hidpp_descriptor[] = {* * Right now, RF report types have the same report types (or report id's) * than the hid report created from those RF reports. In the future -* this doesnt have to be true. +* this doesn't have to be true. * * For instance, RF report type 0x01 which has a size of 8 bytes, corresponds * to hid report id 0x01, this is standard keyboard. Same thing applies to mice
Signature · 1 line
2.16.1