From 8574c1e5a78327d2570b53bb64c8074a9aa2780e Mon Sep 17 00:00:00 2001 From: Pallav Joshi Date: Tue, 10 Jul 2012 10:41:50 +0530 Subject: [PATCH] Xilinx: ARM: I2C: SI570: Driver updated for more error checking Added interface function parameter check to prevent kernel crashing when wrong or invalid parameter is passed Signed-off-by: Davor Joja --- drivers/misc/si570.c | 19 ++++++++++++++----- include/linux/i2c/si570.h | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/misc/si570.c b/drivers/misc/si570.c index fea3a0076d8..8bafd62ccfa 100644 --- a/drivers/misc/si570.c +++ b/drivers/misc/si570.c @@ -78,7 +78,7 @@ struct si570_data { }; -static struct i2c_client *client_i2c; +static struct i2c_client *si570_client; static int si570_get_defaults(struct i2c_client *client) @@ -286,6 +286,9 @@ int get_frequency_si570(struct device *dev, unsigned long *freq) int err; char buf[10+1]; + if ((!dev) || (to_i2c_client(dev) != si570_client)) + return -EINVAL; + show_frequency_attr(dev, NULL, buf); err = strict_strtoul(buf, 10, freq); @@ -340,6 +343,9 @@ int set_frequency_si570(struct device *dev, unsigned long freq) { char buf[10+1]; + if ((!dev) || (to_i2c_client(dev) != si570_client)) + return -EINVAL; + sprintf(buf, "%lu", freq); return set_frequency_attr(dev, NULL, buf, 0); @@ -377,18 +383,21 @@ done: return count; } -void reset_si570(struct device *dev, int id) +int reset_si570(struct device *dev, int id) { char buf[4]; + if ((!dev) || (to_i2c_client(dev) != si570_client)) + return -EINVAL; + sprintf(buf, "%lu", (unsigned long)id); - set_reset_attr(dev, NULL, buf, 0); + return set_reset_attr(dev, NULL, buf, 0); } EXPORT_SYMBOL(reset_si570); struct i2c_client *get_i2c_client_si570(void) { - return client_i2c; + return si570_client; } EXPORT_SYMBOL(get_i2c_client_si570); @@ -510,7 +519,7 @@ static int si570_probe(struct i2c_client *client, initial_fout); } - client_i2c = client; + si570_client = client; return 0; diff --git a/include/linux/i2c/si570.h b/include/linux/i2c/si570.h index 3f957381d13..f2cf28543c7 100644 --- a/include/linux/i2c/si570.h +++ b/include/linux/i2c/si570.h @@ -15,6 +15,8 @@ #define __LINUX_SI570_H #include +#include +#include struct si570_platform_data { u64 factory_fout; /* Factory default output frequency */ @@ -23,7 +25,7 @@ struct si570_platform_data { int get_frequency_si570(struct device *dev, unsigned long *freq); int set_frequency_si570(struct device *dev, unsigned long freq); -void reset_si570(struct device *dev, int id); +int reset_si570(struct device *dev, int id); struct i2c_client *get_i2c_client_si570(void); #endif /* __LINUX_SI570_H */ -- 2.11.4.GIT