diff options
Diffstat (limited to 'drivers/rtc/nvmem.c')
| -rw-r--r-- | drivers/rtc/nvmem.c | 38 |
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 @@ | |||
| 12 | #include <linux/types.h> | 12 | #include <linux/types.h> |
| 13 | #include <linux/nvmem-consumer.h> | 13 | #include <linux/nvmem-consumer.h> |
| 14 | #include <linux/rtc.h> | 14 | #include <linux/rtc.h> |
| 15 | #include <linux/slab.h> | ||
| 15 | #include <linux/sysfs.h> | 16 | #include <linux/sysfs.h> |
| 16 | 17 | ||
| 17 | /* | 18 | /* |
| @@ -25,11 +26,9 @@ rtc_nvram_read(struct file *filp, struct kobject *kobj, | |||
| 25 | struct bin_attribute *attr, | 26 | struct bin_attribute *attr, |
| 26 | char *buf, loff_t off, size_t count) | 27 | char *buf, loff_t off, size_t count) |
| 27 | { | 28 | { |
| 28 | struct rtc_device *rtc = attr->private; | ||
| 29 | |||
| 30 | dev_warn_once(kobj_to_dev(kobj), nvram_warning); | 29 | dev_warn_once(kobj_to_dev(kobj), nvram_warning); |
| 31 | 30 | ||
| 32 | return nvmem_device_read(rtc->nvmem, off, count, buf); | 31 | return nvmem_device_read(attr->private, off, count, buf); |
| 33 | } | 32 | } |
| 34 | 33 | ||
| 35 | static ssize_t | 34 | static ssize_t |
| @@ -37,26 +36,23 @@ rtc_nvram_write(struct file *filp, struct kobject *kobj, | |||
| 37 | struct bin_attribute *attr, | 36 | struct bin_attribute *attr, |
| 38 | char *buf, loff_t off, size_t count) | 37 | char *buf, loff_t off, size_t count) |
| 39 | { | 38 | { |
| 40 | struct rtc_device *rtc = attr->private; | ||
| 41 | |||
| 42 | dev_warn_once(kobj_to_dev(kobj), nvram_warning); | 39 | dev_warn_once(kobj_to_dev(kobj), nvram_warning); |
| 43 | 40 | ||
| 44 | return nvmem_device_write(rtc->nvmem, off, count, buf); | 41 | return nvmem_device_write(attr->private, off, count, buf); |
| 45 | } | 42 | } |
| 46 | 43 | ||
| 47 | static int rtc_nvram_register(struct rtc_device *rtc, size_t size) | 44 | static int rtc_nvram_register(struct rtc_device *rtc, |
| 45 | struct nvmem_device *nvmem, size_t size) | ||
| 48 | { | 46 | { |
| 49 | int err; | 47 | int err; |
| 50 | 48 | ||
| 51 | rtc->nvram = devm_kzalloc(rtc->dev.parent, | 49 | rtc->nvram = kzalloc(sizeof(struct bin_attribute), GFP_KERNEL); |
| 52 | sizeof(struct bin_attribute), | ||
| 53 | GFP_KERNEL); | ||
| 54 | if (!rtc->nvram) | 50 | if (!rtc->nvram) |
| 55 | return -ENOMEM; | 51 | return -ENOMEM; |
| 56 | 52 | ||
| 57 | rtc->nvram->attr.name = "nvram"; | 53 | rtc->nvram->attr.name = "nvram"; |
| 58 | rtc->nvram->attr.mode = 0644; | 54 | rtc->nvram->attr.mode = 0644; |
| 59 | rtc->nvram->private = rtc; | 55 | rtc->nvram->private = nvmem; |
| 60 | 56 | ||
| 61 | sysfs_bin_attr_init(rtc->nvram); | 57 | sysfs_bin_attr_init(rtc->nvram); |
| 62 | 58 | ||
| @@ -67,7 +63,7 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size) | |||
| 67 | err = sysfs_create_bin_file(&rtc->dev.parent->kobj, | 63 | err = sysfs_create_bin_file(&rtc->dev.parent->kobj, |
| 68 | rtc->nvram); | 64 | rtc->nvram); |
| 69 | if (err) { | 65 | if (err) { |
| 70 | devm_kfree(rtc->dev.parent, rtc->nvram); | 66 | kfree(rtc->nvram); |
| 71 | rtc->nvram = NULL; | 67 | rtc->nvram = NULL; |
| 72 | } | 68 | } |
| 73 | 69 | ||
| @@ -77,6 +73,8 @@ static int rtc_nvram_register(struct rtc_device *rtc, size_t size) | |||
| 77 | static void rtc_nvram_unregister(struct rtc_device *rtc) | 73 | static void rtc_nvram_unregister(struct rtc_device *rtc) |
| 78 | { | 74 | { |
| 79 | sysfs_remove_bin_file(&rtc->dev.parent->kobj, rtc->nvram); | 75 | sysfs_remove_bin_file(&rtc->dev.parent->kobj, rtc->nvram); |
| 76 | kfree(rtc->nvram); | ||
| 77 | rtc->nvram = NULL; | ||
| 80 | } | 78 | } |
| 81 | 79 | ||
| 82 | /* | 80 | /* |
| @@ -85,21 +83,20 @@ static void rtc_nvram_unregister(struct rtc_device *rtc) | |||
| 85 | int rtc_nvmem_register(struct rtc_device *rtc, | 83 | int rtc_nvmem_register(struct rtc_device *rtc, |
| 86 | struct nvmem_config *nvmem_config) | 84 | struct nvmem_config *nvmem_config) |
| 87 | { | 85 | { |
| 88 | if (!IS_ERR_OR_NULL(rtc->nvmem)) | 86 | struct nvmem_device *nvmem; |
| 89 | return -EBUSY; | ||
| 90 | 87 | ||
| 91 | if (!nvmem_config) | 88 | if (!nvmem_config) |
| 92 | return -ENODEV; | 89 | return -ENODEV; |
| 93 | 90 | ||
| 94 | nvmem_config->dev = rtc->dev.parent; | 91 | nvmem_config->dev = rtc->dev.parent; |
| 95 | nvmem_config->owner = rtc->owner; | 92 | nvmem_config->owner = rtc->owner; |
| 96 | rtc->nvmem = nvmem_register(nvmem_config); | 93 | nvmem = devm_nvmem_register(rtc->dev.parent, nvmem_config); |
| 97 | if (IS_ERR(rtc->nvmem)) | 94 | if (IS_ERR(nvmem)) |
| 98 | return PTR_ERR(rtc->nvmem); | 95 | return PTR_ERR(nvmem); |
| 99 | 96 | ||
| 100 | /* Register the old ABI */ | 97 | /* Register the old ABI */ |
| 101 | if (rtc->nvram_old_abi) | 98 | if (rtc->nvram_old_abi) |
| 102 | rtc_nvram_register(rtc, nvmem_config->size); | 99 | rtc_nvram_register(rtc, nvmem, nvmem_config->size); |
| 103 | 100 | ||
| 104 | return 0; | 101 | return 0; |
| 105 | } | 102 | } |
| @@ -107,12 +104,7 @@ EXPORT_SYMBOL_GPL(rtc_nvmem_register); | |||
| 107 | 104 | ||
| 108 | void rtc_nvmem_unregister(struct rtc_device *rtc) | 105 | void rtc_nvmem_unregister(struct rtc_device *rtc) |
| 109 | { | 106 | { |
| 110 | if (IS_ERR_OR_NULL(rtc->nvmem)) | ||
| 111 | return; | ||
| 112 | |||
| 113 | /* unregister the old ABI */ | 107 | /* unregister the old ABI */ |
| 114 | if (rtc->nvram) | 108 | if (rtc->nvram) |
| 115 | rtc_nvram_unregister(rtc); | 109 | rtc_nvram_unregister(rtc); |
| 116 | |||
| 117 | nvmem_unregister(rtc->nvmem); | ||
| 118 | } | 110 | } |
