Siano: Adjustments for some function implementations
Subsystems (3)
cover Siano: Adjustments for some function implementations
From: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 12:55:43 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (3):
Delete an error message for a failed memory allocation in three functions Improve a size determination in six functions
Adjust five checks for null pointers
drivers/media/common/siano/smscoreapi.c | 39 ++++++++++++++------------------- 1 file changed, 16 insertions(+), 23 deletions(-)
Signature · 1 line
2.14.1
PATCH 1/3 Siano: Delete an error message for a failed memory allocation in three functions
From: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 12:30:11 +0200
Omit an extra message for a memory allocation failure in these functions.
This issue was detected by using the Coccinelle software.
--- drivers/media/common/siano/smscoreapi.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/media/common/siano/smscoreapi.c +4 -9
@@ -1304,7 +1304,5 @@ static int smscore_init_device(struct smscore_device_t *coredev, int mode) -if (!buffer) { -pr_err ("Could not allocate buffer for init device message.\n" ); +if (!buffer)return -ENOMEM ; - } msg = (struct sms_msg_data *)SMS_ALIGN_ADDRESS (buffer); SMS_INIT_MSG(&msg->x_msg_header, MSG_SMS_INIT_DEVICE_REQ,
@@ -1690,7 +1688,6 @@ static int smscore_validate_client(struct smscore_device_t *coredev, -if (!listentry) { -pr_err ("Can't allocate memory for client id.\n" ); +if (!listentry)return -ENOMEM ; - } + listentry->id = id; listentry->data_type = data_type; list_add_locked(&listentry->entry, &client->idlist,
@@ -1728,7 +1725,5 @@ int smscore_register_client(struct smscore_device_t *coredev, -if (!newclient) { -pr_err ("Failed to allocate memory for client.\n" ); +if (!newclient)return -ENOMEM ; - }INIT_LIST_HEAD (&newclient->idlist); newclient->coredev = coredev;
Signature · 1 line
2.14.1
PATCH 2/3 Siano: Improve a size determination in six functions
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 12:38:39 +0200
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/media/common/siano/smscoreapi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/media/common/siano/smscoreapi.c +6 -8
@@ -447,5 +447,5 @@ static struct smscore_registry_entry_t *smscore_find_registry(char *devpath)return entry; } } - entry =kmalloc (sizeof (struct smscore_registry_entry_t ),GFP_KERNEL ); + entry =kmalloc (sizeof (*entry),GFP_KERNEL );if (entry) {
@@ -536,7 +536,5 @@ int smscore_register_hotplug(hotplug_t hotplug)int rc =0 ;kmutex_lock (&g_smscore_deviceslock); - - notifyee =kmalloc (sizeof (struct smscore_device_notifyee_t ), -GFP_KERNEL ); + notifyee =kmalloc (sizeof (*notifyee),GFP_KERNEL );if (notifyee) {
@@ -627,5 +625,5 @@ smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer, {struct smscore_buffer_t *cb; - cb =kzalloc (sizeof (struct smscore_buffer_t ),GFP_KERNEL ); + cb =kzalloc (sizeof (*cb),GFP_KERNEL );if (!cb)
@@ -655,5 +653,5 @@ int smscore_register_device(struct smsdevice_params_t *params,struct smscore_device_t *dev;u8 *buffer; - dev =kzalloc (sizeof (struct smscore_device_t ),GFP_KERNEL ); + dev =kzalloc (sizeof (*dev),GFP_KERNEL );if (!dev)
@@ -1684,5 +1682,5 @@ static int smscore_validate_client(struct smscore_device_t *coredev,pr_err ("The msg ID already registered to another client.\n" );return -EEXIST ; } - listentry =kzalloc (sizeof (struct smscore_idlist_t ),GFP_KERNEL ); + listentry =kzalloc (sizeof (*listentry),GFP_KERNEL );if (!listentry)
@@ -1721,5 +1719,5 @@ int smscore_register_client(struct smscore_device_t *coredev,return -EEXIST ; } - newclient =kzalloc (sizeof (struct smscore_client_t ),GFP_KERNEL ); + newclient =kzalloc (sizeof (*newclient),GFP_KERNEL );if (!newclient)
Signature · 1 line
2.14.1
PATCH 3/3 Siano: Adjust five checks for null pointers
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Mon, 28 Aug 2017 12:50:28 +0200
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 the affected source code places.
--- drivers/media/common/siano/smscoreapi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/media/common/siano/smscoreapi.c +6 -6
@@ -749,7 +749,7 @@ static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev, void *buffer, size_t size, struct completion *completion) { int rc; -if (completion =NULL ) +if (!completion)return -EINVAL ;init_completion (completion);
@@ -1151,8 +1151,8 @@ static int smscore_load_firmware_from_file(struct smscore_device_t *coredev, }pr_debug ("Firmware name: %s\n" , fw_filename); -if (loadfirmware_handler =NULL && !(coredev->device_flags - &SMS_DEVICE_FAMILY2 )) +if (!loadfirmware_handler && + !(coredev->device_flags &SMS_DEVICE_FAMILY2 ))return -EINVAL ; rc =request_firmware (&fw, fw_filename, coredev->device);
@@ -1789,7 +1789,7 @@ int smsclient_sendrequest(struct smscore_client_t *client,struct sms_msg_hdr *phdr = (struct sms_msg_hdr *) buffer;int rc; -if (client =NULL ) { +if (!client) {pr_err ("Got NULL client\n" );return -EINVAL ; }
@@ -1797,7 +1797,7 @@ int smsclient_sendrequest(struct smscore_client_t *client, coredev = client->coredev;/* check that no other channel with same id exists */ -if (coredev =NULL ) { +if (!coredev) {pr_err ("Got NULL coredev\n" );return -EINVAL ; }
@@ -1954,7 +1954,7 @@ int smscore_gpio_configure(struct smscore_device_t *coredev, u8 pin_num,if (pin_num >MAX_GPIO_PIN_NUMBER )return -EINVAL ; -if (p_gpio_config =NULL ) +if (!p_gpio_config)return -EINVAL ; total_len =sizeof (struct sms_msg_hdr ) + (sizeof (u32) *6 );
Signature · 1 line
2.14.1