2018-01-09 18:27:26

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/5] misc-PTI: Adjustments for some function implementations

From: Markus Elfring <[email protected]>
Date: Tue, 9 Jan 2018 19:06:36 +0100

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (5):
Delete an error message for a failed memory allocation in two functions
Fix a typo in five comment lines
Improve a size determination in two functions
Adjust 11 checks for null pointers
Delete an unnecessary return statement in two functions

drivers/misc/pti.c | 45 +++++++++++++++++++--------------------------
1 file changed, 19 insertions(+), 26 deletions(-)

--
2.15.1


2018-01-09 18:28:40

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/5] misc/pti: Delete an error message for a failed memory allocation in two functions

From: Markus Elfring <[email protected]>
Date: Tue, 9 Jan 2018 18:00:15 +0100

Omit an extra message for a memory allocation failure in these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/pti.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index 41f2a9f6851d..92a1a20839c8 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -619,11 +619,8 @@ static ssize_t pti_char_write(struct file *filp, const char __user *data,
mc = filp->private_data;

kbuf = kmalloc(size, GFP_KERNEL);
- if (kbuf == NULL) {
- pr_err("%s(%d): buf allocation failed\n",
- __func__, __LINE__);
+ if (!kbuf)
return -ENOMEM;
- }

do {
if (len - n > USER_COPY_SIZE)
@@ -826,9 +823,6 @@ static int pti_pci_probe(struct pci_dev *pdev,
drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
if (drv_data == NULL) {
retval = -ENOMEM;
- dev_err(&pdev->dev,
- "%s(%d): kmalloc() returned NULL memory.\n",
- __func__, __LINE__);
goto err_disable_pci;
}
drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
--
2.15.1

2018-01-09 18:29:51

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/5] misc/pti: Fix a typo in five comment lines

From: Markus Elfring <[email protected]>
Date: Tue, 9 Jan 2018 18:18:15 +0100

Adjust words in these descriptions.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/pti.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index 92a1a20839c8..8292e8098cc8 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -378,7 +378,7 @@ EXPORT_SYMBOL_GPL(pti_release_masterchannel);
* @buf: Trace debuging data to write to the PTI HW.
* Null value will return with no write occurring.
* @count: Size of buf. Value of 0 or a negative number will
- * return with no write occuring.
+ * return with no write occurring.
*/
void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
{
@@ -403,7 +403,7 @@ EXPORT_SYMBOL_GPL(pti_writedata);
* ID to the PTI device via tty device.
*
* @tty: tty interface.
- * @filp: filp interface pased to tty_port_open() call.
+ * @filp: filp interface passed to tty_port_open() call.
*
* Returns:
* int, 0 for success
@@ -435,7 +435,7 @@ static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
* master, channel aperture ID to the PTI device via tty device.
*
* @tty: tty interface.
- * @filp: filp interface pased to tty_port_close() call.
+ * @filp: filp interface passed to tty_port_close() call.
*
* The main purpose of using the tty device interface is to route
* syslog daemon messages to the PTI HW and out of the handheld platform
@@ -572,7 +572,7 @@ static int pti_char_open(struct inode *inode, struct file *filp)
* pti_char_release()- Close a char channel to the PTI device. Part
* of the misc device implementation.
*
- * @inode: Not used in this implementaiton.
+ * @inode: Not used in this implementation.
* @filp: Contains private_data that contains the master, channel
* ID to be released by the PTI device.
*
@@ -668,7 +668,7 @@ static struct miscdevice pti_char_driver = {
/**
* pti_console_write()- Write to the console that has been acquired.
*
- * @c: Not used in this implementaiton.
+ * @c: Not used in this implementation.
* @buf: Data to be written.
* @len: Length of buf.
*/
--
2.15.1

2018-01-09 18:31:23

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/5] misc/pti: Improve a size determination in two functions

From: Markus Elfring <[email protected]>
Date: Tue, 9 Jan 2018 18:28:44 +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.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/pti.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index 8292e8098cc8..8ae79b286573 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -243,10 +243,9 @@ static struct pti_masterchannel *get_id(u8 *id_array,
int base_id,
const char *thread_name)
{
- struct pti_masterchannel *mc;
int i, j, mask;
+ struct pti_masterchannel *mc = kmalloc(sizeof(*mc), GFP_KERNEL);

- mc = kmalloc(sizeof(struct pti_masterchannel), GFP_KERNEL);
if (mc == NULL)
return NULL;

@@ -465,7 +464,7 @@ static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
int ret = tty_standard_install(driver, tty);

if (ret == 0) {
- pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+ pti_tty_data = kmalloc(sizeof(*pti_tty_data), GFP_KERNEL);
if (pti_tty_data == NULL)
return -ENOMEM;

--
2.15.1

2018-01-09 18:32:35

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 4/5] misc/pti: Adjust 11 checks for null pointers

From: Markus Elfring <[email protected]>
Date: Tue, 9 Jan 2018 18:48:10 +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 the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/pti.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index 8ae79b286573..11d92c3f43ba 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -246,7 +246,7 @@ static struct pti_masterchannel *get_id(u8 *id_array,
int i, j, mask;
struct pti_masterchannel *mc = kmalloc(sizeof(*mc), GFP_KERNEL);

- if (mc == NULL)
+ if (!mc)
return NULL;

/* look for a byte with a free bit */
@@ -386,5 +386,5 @@ void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
* API function, thus, all parameters should
* be checked for validity.
*/
- if ((mc != NULL) && (buf != NULL) && (count > 0))
+ if (mc && buf && count > 0)
pti_write_to_aperture(mc, buf, count);
@@ -465,7 +465,7 @@ static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)

if (ret == 0) {
pti_tty_data = kmalloc(sizeof(*pti_tty_data), GFP_KERNEL);
- if (pti_tty_data == NULL)
+ if (!pti_tty_data)
return -ENOMEM;

if (idx == PTITTY_MINOR_START)
@@ -473,7 +473,7 @@ static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
else
pti_tty_data->mc = pti_request_masterchannel(2, NULL);

- if (pti_tty_data->mc == NULL) {
+ if (!pti_tty_data->mc) {
kfree(pti_tty_data);
return -ENXIO;
}
@@ -492,7 +492,8 @@ static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
static void pti_tty_cleanup(struct tty_struct *tty)
{
struct pti_tty *pti_tty_data = tty->driver_data;
- if (pti_tty_data == NULL)
+
+ if (!pti_tty_data)
return;
pti_release_masterchannel(pti_tty_data->mc);
kfree(pti_tty_data);
@@ -516,7 +517,8 @@ static int pti_tty_driver_write(struct tty_struct *tty,
const unsigned char *buf, int len)
{
struct pti_tty *pti_tty_data = tty->driver_data;
- if ((pti_tty_data != NULL) && (pti_tty_data->mc != NULL)) {
+
+ if (pti_tty_data && pti_tty_data->mc) {
pti_write_to_aperture(pti_tty_data->mc, (u8 *)buf, len);
return len;
}
@@ -561,7 +563,7 @@ static int pti_char_open(struct inode *inode, struct file *filp)
* Slightly easier to debug if this driver needs debugging.
*/
mc = pti_request_masterchannel(0, NULL);
- if (mc == NULL)
+ if (!mc)
return -ENOMEM;
filp->private_data = mc;
return 0;
@@ -820,7 +822,7 @@ static int pti_pci_probe(struct pci_dev *pdev,
}

drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
- if (drv_data == NULL) {
+ if (!drv_data) {
retval = -ENOMEM;
goto err_disable_pci;
}
@@ -916,7 +918,7 @@ static int __init pti_init(void)
/* First register module as tty device */

pti_tty_driver = alloc_tty_driver(PTITTY_MINOR_NUM);
- if (pti_tty_driver == NULL) {
+ if (!pti_tty_driver) {
pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
__func__, __LINE__);
return -ENOMEM;
--
2.15.1

2018-01-09 18:33:32

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 5/5] misc/pti: Delete an unnecessary return statement in two functions

From: Markus Elfring <[email protected]>
Date: Tue, 9 Jan 2018 18:52:36 +0100

The script "checkpatch.pl" pointed information out like the following.

WARNING: void function return statements are not generally useful

Thus remove such a statement in the affected functions.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/pti.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index 11d92c3f43ba..7f9235e56cc0 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -142,7 +142,6 @@ static void pti_write_to_aperture(struct pti_masterchannel *mc,
ptiword |= *p++ << (24-(8*i));

iowrite32(ptiword, aperture);
- return;
}

/**
@@ -390,5 +389,4 @@ void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
pti_write_to_aperture(mc, buf, count);
- return;
}
EXPORT_SYMBOL_GPL(pti_writedata);

--
2.15.1