Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01e2708a authored by Himanshu Aggarwal's avatar Himanshu Aggarwal Committed by Gerrit - the friendly Code Review server
Browse files

input: misc: pat9125: fix issues found in static analysis



Fix the following issues found in static analysis:
- missing blank lines after declarations
- unnecessary return in a void function
- exporting world writable files is usually an error
- block comments use * on subsequent and trailing lines
- Add DT binding description and vendor prefixe for the
driver.
- Add Linux Foundation copyright markings.

Change-Id: Id2ed9a6d4e31bd2acd3185bf7ef9c78f8a41cf36
Signed-off-by: default avatarHimanshu Aggarwal <haggarwa@codeaurora.org>
Signed-off-by: default avatarVevek Venkatesan <vevekv@codeaurora.org>
Signed-off-by: default avatarShantanu Jain <shjain@codeaurora.org>
parent 4e09168f
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
PixArt pat9125 rotating switch

The Pixart's PAT9125 controller is connected to the host processor via I2C.
It detects the rotation when user rotates the switch and generates interrupt
to the Host processor. The host processor reads the direction and number of
steps over I2C and passes the data to the rest of the system.

Required properties:

 - compatible		: should be "pixart,pat9125".
+1 −0
Original line number Diff line number Diff line
@@ -175,6 +175,7 @@ parade Parade Technologies Inc.
pericom	Pericom Technology Inc.
phytec	PHYTEC Messtechnik GmbH
picochip	Picochip Ltd
pixart	PixArt Imaging Inc
plathome	Plat'Home Co., Ltd.
plda	PLDA
pixcir  PIXCIR MICROELECTRONICS Co., Ltd
+21 −43
Original line number Diff line number Diff line
/* drivers/input/misc/ots_pat9125/pat9125_linux_driver.c
 *
 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
 *
 */

#include <linux/kernel.h>
#include <linux/input.h>
@@ -26,11 +31,10 @@ static struct pat9125_linux_data_t pat9125data;
static int pat9125_i2c_write(u8 reg, u8 *data, int len);
static int pat9125_i2c_read(u8 reg, u8 *data);

/**************************************/

extern unsigned char ReadData(unsigned char addr)
{
	u8 data = 0xff;

	pat9125_i2c_read(addr, &data);
	return data;
}
@@ -42,7 +46,6 @@ extern void delay_ms(int ms)
{
	msleep(ms);
}
/**************************************/
static int pat9125_i2c_write(u8 reg, u8 *data, int len)
{
	u8  buf[20];
@@ -84,9 +87,11 @@ static int pat9125_i2c_read(u8 reg, u8 *data)

	buf[0] = reg;

	/* If everything went ok (i.e. 1 msg transmitted),
	return #bytes  transmitted, else error code.
	thus if transmit is ok  return value 1 */
	/*
	 * If everything went ok (i.e. 1 msg transmitted),
	 *return #bytes  transmitted, else error code.
	 * thus if transmit is ok  return value 1
	 */
	rc = i2c_master_send(pat9125data.client, buf, 1);
	if (rc != 1) {
		pr_debug(
@@ -115,7 +120,6 @@ void pixart_pat9125_ist(void)

static irqreturn_t pixart_pat9125_irq(int irq, void *handle)
{
/* "cat /proc/kmsg" to see kernel message */
	pixart_pat9125_ist();
	return IRQ_HANDLED;
}
@@ -139,36 +143,29 @@ static int pat9125_start(void)

static void pat9125_stop(void)
{
	 pr_debug(">>> %s (%d)\n", __func__, __LINE__);
	free_irq(pat9125data.irq, &pat9125data);
}

static ssize_t pat9125_fops_read(struct file *filp,
	char *buf, size_t count, loff_t *l)
{
	 pr_debug(">>> %s (%d)\n", __func__, __LINE__);
	return 0;
}

static ssize_t pat9125_fops_write(struct file *filp,
	const char *buf, size_t count, loff_t *f_ops)
{
	 pr_debug(">>> %s (%d)\n", __func__, __LINE__);
	return 0;
}

static long pat9125_fops_ioctl(struct file *file,
	unsigned int cmd, unsigned long arg)
/* static int pat9125_fops_ioctl(struct inode *inode,
	struct file *file, unsigned int cmd, unsigned long arg) */
{
	 pr_debug(">>> %s (%d)\n", __func__, __LINE__);
	return 0;
}

static int pat9125_fops_open(struct inode *inode, struct file *filp)
{
	 pr_debug(">>> %s (%d)\n", __func__, __LINE__);
	return 0;
}

@@ -209,6 +206,7 @@ static ssize_t pat9125_test_store(struct device *dev,
	/* example(in console): echo w 12 34 > rw_reg */
	if (*p == 'w') {
		long write_addr, write_data;

		p += 2;
		if (!kstrtol(p, 16, &write_addr)) {
			p += 3;
@@ -222,10 +220,12 @@ static ssize_t pat9125_test_store(struct device *dev,
		/* example(in console): echo r 12 > rw_reg */
	}	else if (*p == 'r')	{
		long read_addr;

		p += 2;

		if (!kstrtol(p, 16, &read_addr)) {
			int data = 0;

			data = ReadData((u8)read_addr);
			pr_debug(
				"r 0x%x 0x%x\n",
@@ -246,20 +246,18 @@ static ssize_t pat9125_test_show(
}
static DEVICE_ATTR(
	test,
	S_IRUGO | S_IWUGO , pat9125_test_show, pat9125_test_store);
	S_IRUGO | S_IWUSR | S_IWGRP, pat9125_test_show, pat9125_test_store);
static struct device_attribute *pat9125_attr_list[] = {
	&dev_attr_test,
};


/*----------------------------------------------------------------------------*/
static int pat9125_create_attr(struct device *dev)
{
	int idx, err = 0;
	int num = (int)(sizeof(pat9125_attr_list)/sizeof(pat9125_attr_list[0]));
	int num = ARRAY_SIZE(pat9125_attr_list);

	if (!dev)
		return -EINVAL;

	for (idx = 0; idx < num; idx++) {
		err = device_create_file(dev, pat9125_attr_list[idx]);
		if (err) {
@@ -269,21 +267,6 @@ static int pat9125_create_attr(struct device *dev)
			break;
		}
	}

	return err;
}
/*----------------------------------------------------------------------------*/
static int pat9125_delete_attr(struct device *dev)
{

	int idx , err = 0;
	int num = (int)(sizeof(pat9125_attr_list)/sizeof(pat9125_attr_list[0]));
	if (!dev)
		return -EINVAL;

	for (idx = 0; idx < num; idx++)
		device_remove_file(dev, pat9125_attr_list[idx]);

	return err;
}

@@ -400,7 +383,7 @@ static const struct dev_pm_ops pat9125_pm_ops = {
	.resume = pat9125_resume
};

static struct of_device_id pixart_pat9125_match_table[] = {
static const struct of_device_id pixart_pat9125_match_table[] = {
	{ .compatible = "pixart,pat9125",},
	{ },
};
@@ -462,10 +445,6 @@ static int pat9125_init_input_data(void)

static int __init pat9125_linux_init(void)
{
	 pr_debug("%s (%d) :init module\n", __func__, __LINE__);
	 pr_debug("Date : %s\n", __DATE__);
	 pr_debug("Time : %s\n", __TIME__);

	return i2c_add_driver(&pat9125_i2c_driver);
}

@@ -477,7 +456,6 @@ static void __exit pat9125_linux_exit(void)
	 pr_debug("%s (%d) : exit module\n", __func__, __LINE__);
	pat9125_stop();
	misc_register(&pat9125_device);
	pat9125_delete_attr(pat9125data.pat9125_device);
	i2c_del_driver(&pat9125_i2c_driver);
}

+21 −10
Original line number Diff line number Diff line
/* drivers/input/misc/ots_pat9125/pixart_ots.c
 *
 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
 *
 */

#include "pixart_ots.h"

@@ -7,22 +12,29 @@ bool OTS_Sensor_Init(void)
{
	unsigned char sensor_pid = 0, read_id_ok = 0;

	/* Read sensor_pid in address 0x00 to check if the
	 serial link is valid, read value should be 0x31. */
	/*
	 * Read sensor_pid in address 0x00 to check if the
	  * serial link is valid, read value should be 0x31.
	 */
	sensor_pid = ReadData(0x00);

	if (sensor_pid == 0x31) {
		read_id_ok = 1;

		/* PAT9125 sensor recommended settings: */
		/* switch to bank0, not allowed to perform OTS_RegWriteRead */
		/*
		 *PAT9125 sensor recommended settings:
		 * switch to bank0, not allowed to perform OTS_RegWriteRead
		 */
		WriteData(0x7F, 0x00);
		/* software reset (i.e. set bit7 to 1).
		It will reset to 0 automatically */
		/* so perform OTS_RegWriteRead is not allowed. */
		/*
		 * software reset (i.e. set bit7 to 1).
		 * It will reset to 0 automatically
		 * so perform OTS_RegWriteRead is not allowed.
		 */
		WriteData(0x06, 0x97);

		delay_ms(1);				/* delay 1ms */
		/* delay 1ms */
		delay_ms(1);

		/* disable write protect */
		OTS_WriteRead(0x09, 0x5A);
@@ -48,6 +60,7 @@ bool OTS_Sensor_Init(void)
static void OTS_WriteRead(uint8_t address, uint8_t wdata)
{
	uint8_t read_value;

	do {
		/* Write data to specified address */
		WriteData(address, wdata);
@@ -55,6 +68,4 @@ static void OTS_WriteRead(uint8_t address, uint8_t wdata)
		read_value = ReadData(address);
		/* Check if the data is correctly written */
	} while (read_value != wdata);
	return;
}
+6 −0
Original line number Diff line number Diff line
/* drivers/input/misc/ots_pat9125/pixart_ots.h
 *
 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
 *
 */

#ifndef _PIXART_OTS_H_
#define _PIXART_OTS_H_

Loading