Returning a valid time when the time is invalid is a bad practice, because
then userspace is not able to react on the information. Also, it doesn't
make sense to return epoch because it is already the default time.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Returning a valid time when the time is invalid is a bad practice, because
then userspace is not able to react on the information. Also, it doesn't
make sense to return epoch because it is already the default time.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The shifting of buf[5] by 24 bits to the left will be promoted to
a 32 bit signed int and then sign-extended to an unsigned long. If
the top bit of buf[5] is set then all then all the upper bits sec
end up as also being set because of the sign-extension. Fix this by
casting buf[5] to an unsigned long before the shift.
Detected by CoverityScan, CID#1465292 ("Unintended sign extension")
Fixes: 0e1492330c ("rtc: add rtc-tx4939 driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Since commit 34ce71a96d ("ALSA: timer: remove legacy rtctimer"), the
rtc_register/rtc_control/rtc_unregister API is unused. As it is highly
unlikely to be needed again, remove it.
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
After successful
sr = isl1208_i2c_set_regs(client, 0, regs, ISL1208_RTC_SECTION_LEN);
sr will be 0.
As a result
sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR,
sr & ~ISL1208_REG_SR_WRTC);
is equal to
sr = i2c_smbus_write_byte_data(client, ISL1208_REG_SR, 0);
which clears all flags in SR.
Add an additional read of SR, to have value of SR in sr again.
Signed-off-by: Denis Osterland <Denis.Osterland@diehl.com>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The rtc-tx4939 driver now compiles correctly on other architectures, add
COMPILE_TEST to improve code coverage.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Copy RTC definitions from arch/mips/include/asm/txx9/tx4939.h to the RTC
driver so it doesn't depend on arch/mips anymore.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Currently, the IRQs are disabled when the rtc driver is removed (e.g. when
shutting down the platform).
This means that the RTC will be unable to wakeup the platform.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver, use the core to
register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The probe function is not allowed to fail after registering the RTC because
the following may happen:
CPU0: CPU1:
sys_load_module()
do_init_module()
do_one_initcall()
cmos_do_probe()
rtc_device_register()
__register_chrdev()
cdev->owner = struct module*
open("/dev/rtc0")
rtc_device_unregister()
module_put()
free_module()
module_free(mod->module_core)
/* struct module *module is now
freed */
chrdev_open()
spin_lock(cdev_lock)
cdev_get()
try_module_get()
module_is_live()
/* dereferences already
freed struct module* */
Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc
as late as possible.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver, use the
core to register an nvmem device. This allows to use the in-kernel
interface to access the nvram.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The probe function is not allowed to fail after registering the RTC because
the following may happen:
CPU0: CPU1:
sys_load_module()
do_init_module()
do_one_initcall()
cmos_do_probe()
rtc_device_register()
__register_chrdev()
cdev->owner = struct module*
open("/dev/rtc0")
rtc_device_unregister()
module_put()
free_module()
module_free(mod->module_core)
/* struct module *module is now
freed */
chrdev_open()
spin_lock(cdev_lock)
cdev_get()
try_module_get()
module_is_live()
/* dereferences already
freed struct module* */
Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc
as late as possible.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Currently, the IRQs are disabled when the rtc driver is removed (e.g. when
shutting down the platform).
This means that the RTC will be unable to wakeup the platform.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Instead of adding a binary sysfs attribute from the driver (which suffers
from a race condition as the attribute appears after the device), use the
core to register an nvmem device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
A documented ABI already exists to get information about the alarm. It is
the only one that is used.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Because nvmem_config is only used and copied at nvmem registration, remove
it from struct rtc_device.
All the rtc drivers using nvmem are now calling rtc_nvmem_register
directly.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
The probe function is not allowed to fail after registering the RTC. Call
rtc_register_device() at the end.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Move m48t86_nvmem_cfg to the stack of m48t86_rtc_probe. This results in a
very small code size reduction and make it safer on systems with two
similar RTCs:
text data bss dec hex filename
1733 164 0 1897 769 drivers/rtc/rtc-m48t86.o.before
1793 100 0 1893 765 drivers/rtc/rtc-m48t86.o.after
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Move ds1511_nvmem_cfg to the stack of ds1511_rtc_probe. This results in a
very small code size reduction and make it safer on systems with two
similar RTCs:
text data bss dec hex filename
2128 164 4 2296 8f8 drivers/rtc/rtc-ds1511.o.before
2175 100 4 2279 8e7 drivers/rtc/rtc-ds1511.o.after
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Avoid allocating memory for struct nvmem_config as it is only necessary at
the nvmem registration.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Call rtc_nvmem_register instead of letting the core do it and stop using
the nvmem_config member of struct rtc_device.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Export rtc_nvmem_register() so it can be called from drivers instead of
only the core.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Switch the parent of the nvmem device to the parent of the rtc device so it
can be registered before the RTC.
This is a small change in the ABI as the nvmem moves out of the
/sys/class/rtc/rtcX folder to be under the parent device folder (that is
where the previous nvram files where registered).
However, it is still available under its correct location,
/sys/bus/nvmem/devices which is the one that should be used by userspace
applications.
The other benefit is that the nvmem device can stay registered even if the
rtc registration fails. Or it is possible to not register the rtc if the
nvmem registration failed.
Finally, it makes a lot of sense for devices that actually have different
i2c or spi addresses for the RTC and the EEPROM. That is basically how it
would end up when using MFD or even completely separate devices.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Make rtc_nvmem_register return -EBUSY when an nvmem is already registered
for that RTC.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>