mempolicy: ERR_PTR dereference in mpol_shared_policy_init()
[safe/jmp/linux-2.6] / drivers / rtc / rtc-pcf8563.c
index 748a502..1af42b4 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/i2c.h>
 #include <linux/bcd.h>
 #include <linux/rtc.h>
+#include <linux/slab.h>
 
 #define DRV_VERSION "0.4.3"
 
@@ -97,13 +98,13 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
                buf[8]);
 
 
-       tm->tm_sec = BCD2BIN(buf[PCF8563_REG_SC] & 0x7F);
-       tm->tm_min = BCD2BIN(buf[PCF8563_REG_MN] & 0x7F);
-       tm->tm_hour = BCD2BIN(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */
-       tm->tm_mday = BCD2BIN(buf[PCF8563_REG_DM] & 0x3F);
+       tm->tm_sec = bcd2bin(buf[PCF8563_REG_SC] & 0x7F);
+       tm->tm_min = bcd2bin(buf[PCF8563_REG_MN] & 0x7F);
+       tm->tm_hour = bcd2bin(buf[PCF8563_REG_HR] & 0x3F); /* rtc hr 0-23 */
+       tm->tm_mday = bcd2bin(buf[PCF8563_REG_DM] & 0x3F);
        tm->tm_wday = buf[PCF8563_REG_DW] & 0x07;
-       tm->tm_mon = BCD2BIN(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
-       tm->tm_year = BCD2BIN(buf[PCF8563_REG_YR]);
+       tm->tm_mon = bcd2bin(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
+       tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]);
        if (tm->tm_year < 70)
                tm->tm_year += 100;     /* assume we are in 1970...2069 */
        /* detect the polarity heuristically. see note above. */
@@ -138,17 +139,17 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
                tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
 
        /* hours, minutes and seconds */
-       buf[PCF8563_REG_SC] = BIN2BCD(tm->tm_sec);
-       buf[PCF8563_REG_MN] = BIN2BCD(tm->tm_min);
-       buf[PCF8563_REG_HR] = BIN2BCD(tm->tm_hour);
+       buf[PCF8563_REG_SC] = bin2bcd(tm->tm_sec);
+       buf[PCF8563_REG_MN] = bin2bcd(tm->tm_min);
+       buf[PCF8563_REG_HR] = bin2bcd(tm->tm_hour);
 
-       buf[PCF8563_REG_DM] = BIN2BCD(tm->tm_mday);
+       buf[PCF8563_REG_DM] = bin2bcd(tm->tm_mday);
 
        /* month, 1 - 12 */
-       buf[PCF8563_REG_MO] = BIN2BCD(tm->tm_mon + 1);
+       buf[PCF8563_REG_MO] = bin2bcd(tm->tm_mon + 1);
 
        /* year and century */
-       buf[PCF8563_REG_YR] = BIN2BCD(tm->tm_year % 100);
+       buf[PCF8563_REG_YR] = bin2bcd(tm->tm_year % 100);
        if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100))
                buf[PCF8563_REG_MO] |= PCF8563_MO_C;
 
@@ -179,58 +180,6 @@ struct pcf8563_limit
        unsigned char max;
 };
 
-static int pcf8563_validate_client(struct i2c_client *client)
-{
-       int i;
-
-       static const struct pcf8563_limit pattern[] = {
-               /* register, mask, min, max */
-               { PCF8563_REG_SC,       0x7F,   0,      59      },
-               { PCF8563_REG_MN,       0x7F,   0,      59      },
-               { PCF8563_REG_HR,       0x3F,   0,      23      },
-               { PCF8563_REG_DM,       0x3F,   0,      31      },
-               { PCF8563_REG_MO,       0x1F,   0,      12      },
-       };
-
-       /* check limits (only registers with bcd values) */
-       for (i = 0; i < ARRAY_SIZE(pattern); i++) {
-               int xfer;
-               unsigned char value;
-               unsigned char buf = pattern[i].reg;
-
-               struct i2c_msg msgs[] = {
-                       { client->addr, 0, 1, &buf },
-                       { client->addr, I2C_M_RD, 1, &buf },
-               };
-
-               xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
-
-               if (xfer != ARRAY_SIZE(msgs)) {
-                       dev_err(&client->dev,
-                               "%s: could not read register 0x%02X\n",
-                               __func__, pattern[i].reg);
-
-                       return -EIO;
-               }
-
-               value = BCD2BIN(buf & pattern[i].mask);
-
-               if (value > pattern[i].max ||
-                       value < pattern[i].min) {
-                       dev_dbg(&client->dev,
-                               "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
-                               "max=%d, value=%d, raw=0x%02X\n",
-                               __func__, i, pattern[i].reg, pattern[i].mask,
-                               pattern[i].min, pattern[i].max,
-                               value, buf);
-
-                       return -ENODEV;
-               }
-       }
-
-       return 0;
-}
-
 static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
        return pcf8563_get_datetime(to_i2c_client(dev), tm);
@@ -262,14 +211,10 @@ static int pcf8563_probe(struct i2c_client *client,
        if (!pcf8563)
                return -ENOMEM;
 
-       /* Verify the chip is really an PCF8563 */
-       if (pcf8563_validate_client(client) < 0) {
-               err = -ENODEV;
-               goto exit_kfree;
-       }
-
        dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
 
+       i2c_set_clientdata(client, pcf8563);
+
        pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name,
                                &client->dev, &pcf8563_rtc_ops, THIS_MODULE);
 
@@ -278,8 +223,6 @@ static int pcf8563_probe(struct i2c_client *client,
                goto exit_kfree;
        }
 
-       i2c_set_clientdata(client, pcf8563);
-
        return 0;
 
 exit_kfree: