From: Andrew Morton <akpm@linux-foundation.org>
To: rtc-linux@googlegroups.com
Cc: Raghavendra Ganiga <ravi23ganiga@gmail.com>,
a.zummo@towertech.it, linux-kernel@vger.kernel.org
Subject: Re: [rtc-linux] [PATCH] rtc: add support of nvram for maxim dallas rtc ds1343
Date: Fri, 20 Jun 2014 15:54:26 -0700 [thread overview]
Message-ID: <20140620155426.1c4d0a9936859d1b20679bdf@linux-foundation.org> (raw)
In-Reply-To: <1400947473-19955-1-git-send-email-ravi23ganiga@gmail.com>
On Sat, 24 May 2014 21:34:33 +0530 Raghavendra Ganiga <ravi23ganiga@gmail.com> wrote:
> This is a patch to add support of nvram for maxim dallas
> rtc ds1343
>
> ...
>
> --- a/drivers/rtc/rtc-ds1343.c
> +++ b/drivers/rtc/rtc-ds1343.c
> @@ -4,6 +4,7 @@
> * Real Time Clock
> *
> * Author : Raghavendra Chandra Ganiga <ravi23ganiga@gmail.com>
> + * Ankur Srivastava <sankurece@gmail.com> : DS1343 Nvram Support
> *
> * This program is free software; you can redistribute it and/or modify
> * it under the terms of the GNU General Public License version 2 as
> @@ -45,6 +46,9 @@
> #define DS1343_CONTROL_REG 0x0F
> #define DS1343_STATUS_REG 0x10
> #define DS1343_TRICKLE_REG 0x11
> +#define DS1343_NVRAM 0x20
> +
> +#define DS1343_NVRAM_LEN 96
>
> /* DS1343 Control Registers bits */
> #define DS1343_EOSC 0x80
> @@ -149,6 +153,64 @@ static ssize_t ds1343_store_glitchfilter(struct device *dev,
> static DEVICE_ATTR(glitch_filter, S_IRUGO | S_IWUSR, ds1343_show_glitchfilter,
> ds1343_store_glitchfilter);
>
> +static ssize_t ds1343_nvram_write(struct file *filp, struct kobject *kobj,
> + struct bin_attribute *attr,
> + char *buf, loff_t off, size_t count)
> +{
> + int ret;
> + unsigned char address;
> + struct device *dev = kobj_to_dev(kobj);
> + struct ds1343_priv *priv = dev_get_drvdata(dev);
> +
> + if (unlikely(!count))
> + return count;
> +
> + if ((count + off) > DS1343_NVRAM_LEN)
I worry about what happens if (count + off) wraps through zero.
> + count = DS1343_NVRAM_LEN - off;
We might end up with an enormous value in `count'?
> + address = DS1343_NVRAM + off;
> +
> + ret = regmap_bulk_write(priv->map, address, buf, count);
> + if (ret < 0)
> + dev_err(&priv->spi->dev, "Error in nvram write %d", ret);
> +
> + return (ret < 0) ? ret : count;
> +}
> +
> +
> +static ssize_t ds1343_nvram_read(struct file *filp, struct kobject *kobj,
> + struct bin_attribute *attr,
> + char *buf, loff_t off, size_t count)
> +{
> + int ret;
> + unsigned char address;
> + struct device *dev = kobj_to_dev(kobj);
> + struct ds1343_priv *priv = dev_get_drvdata(dev);
> +
> + if (unlikely(!count))
> + return count;
> +
> + if ((count + off) > DS1343_NVRAM_LEN)
> + count = DS1343_NVRAM_LEN - off;
Here too.
> + address = DS1343_NVRAM + off;
> +
> + ret = regmap_bulk_read(priv->map, address, buf, count);
> + if (ret < 0)
> + dev_err(&priv->spi->dev, "Error in nvram read %d\n", ret);
> +
> + return (ret < 0) ? ret : count;
> +}
> +
> +
prev parent reply other threads:[~2014-06-20 22:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-24 16:04 Raghavendra Ganiga
2014-06-20 22:54 ` Andrew Morton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140620155426.1c4d0a9936859d1b20679bdf@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=a.zummo@towertech.it \
--cc=linux-kernel@vger.kernel.org \
--cc=ravi23ganiga@gmail.com \
--cc=rtc-linux@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®