summaryrefslogtreecommitdiffstats
path: root/drivers/rtc/nvmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/nvmem.c')
-rw-r--r--drivers/rtc/nvmem.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/drivers/rtc/nvmem.c b/drivers/rtc/nvmem.c
index 36ab183c42f1..dce518d5e50e 100644
--- a/drivers/rtc/nvmem.c
+++ b/drivers/rtc/nvmem.c
@@ -12,6 +12,7 @@
#include <linux/types.h>
#include <linux/nvmem-consumer.h>
#include <linux/rtc.h>
+#include <linux/slab.h>
#include <linux/sysfs.h>
/*
@@ -25,11 +26,9 @@ rtc_nvram_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
- struct rtc_device *rtc = attr->private;
-
dev_warn_once(kobj_to_dev(kobj), nvram_warning);
- return nvmem_device_read(rtc->nvmem, off, count, buf);
+ return nvmem_device_read(attr->private, off, count, buf);
}
static ssize_t
@@ -37,26 +36,23 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr,
char *buf, loff_t off, size_t count)
{
- struct rtc_device *rtc = attr->private;
-
dev_warn_once(kobj_to_dev(kobj), nvram_warning);
- return nvmem_device_write(rtc->nvmem, off, count, buf);
+ return nvmem_device_write(attr->private, off, count, buf);
}
-static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
+static int rtc_nvram_register(struct rtc_device *rtc,
+ struct nvmem_device *nvmem, size_t size)
{
int err;
- rtc->nvram = devm_kzalloc(rtc->dev.parent,
- sizeof(struct bin_attribute),
- GFP_KERNEL);
+ rtc->nvram = kzalloc(sizeof(struct bin_attribute), GFP_KERNEL);
if (!rtc->nvram)
return -ENOMEM;
rtc->nvram->attr.name = "nvram";
rtc->nvram->attr.mode = 0644;
- rtc->nvram->private = rtc;
+ rtc->nvram->private = nvmem;
sysfs_bin_attr_init(rtc->nvram);
@@ -67,7 +63,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
err = sysfs_create_bin_file(&rtc->dev.parent->kobj,
rtc->nvram);
if (err) {
- devm_kfree(rtc->dev.parent, rtc->nvram);
+ kfree(rtc->nvram);
rtc->nvram = NULL;
}
@@ -77,6 +73,8 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size)
static void rtc_nvram_unregister(struct rtc_device *rtc)
{
sysfs_remove_bin_file(&rtc->dev.parent->kobj, rtc->nvram);
+ kfree(rtc->nvram);
+ rtc->nvram = NULL;
}
/*
@@ -85,21 +83,20 @@ static void rtc_nvram_unregister(struct rtc_device *rtc)
int rtc_nvmem_register(struct rtc_device *rtc,
struct nvmem_config *nvmem_config)
{
- if (!IS_ERR_OR_NULL(rtc->nvmem))
- return -EBUSY;
+ struct nvmem_device *nvmem;
if (!nvmem_config)
return -ENODEV;
nvmem_config->dev = rtc->dev.parent;
nvmem_config->owner = rtc->owner;
- rtc->nvmem = nvmem_register(nvmem_config);
- if (IS_ERR(rtc->nvmem))
- return PTR_ERR(rtc->nvmem);
+ nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config);
+ if (IS_ERR(nvmem))
+ return PTR_ERR(nvmem);
/* Register the old ABI */
if (rtc->nvram_old_abi)
- rtc_nvram_register(rtc, nvmem_config->size);
+ rtc_nvram_register(rtc, nvmem, nvmem_config->size);
return 0;
}
@@ -107,12 +104,7 @@ EXPORT_SYMBOL_GPL(rtc_nvmem_register);
void rtc_nvmem_unregister(struct rtc_device *rtc)
{
- if (IS_ERR_OR_NULL(rtc->nvmem))
- return;
-
/* unregister the old ABI */
if (rtc->nvram)
rtc_nvram_unregister(rtc);
-
- nvmem_unregister(rtc->nvmem);
}
OpenPOWER on IntegriCloud