From 61598093bbdd283a7edc367d900f223070ead8d2 Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Fri, 10 May 2024 07:43:03 +0000 Subject: [PATCH] add ax88772C AX88772C_eeprom_tools --- kernel/drivers/rtc/nvmem.c | 43 ++++++++++++++++--------------------------- 1 files changed, 16 insertions(+), 27 deletions(-) diff --git a/kernel/drivers/rtc/nvmem.c b/kernel/drivers/rtc/nvmem.c index 36ab183..4312096 100644 --- a/kernel/drivers/rtc/nvmem.c +++ b/kernel/drivers/rtc/nvmem.c @@ -1,17 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 /* * RTC subsystem, nvmem interface * * Copyright (C) 2017 Alexandre Belloni - * - * 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 - * published by the Free Software Foundation. */ #include <linux/err.h> #include <linux/types.h> #include <linux/nvmem-consumer.h> #include <linux/rtc.h> +#include <linux/slab.h> #include <linux/sysfs.h> /* @@ -25,11 +23,9 @@ 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 +33,23 @@ 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(*rtc->nvram), 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 +60,7 @@ 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 +70,8 @@ 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 +80,20 @@ 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 +101,7 @@ 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); } -- Gitblit v1.6.2