mirror of
https://github.com/torvalds/linux.git
synced 2024-12-02 09:01:34 +00:00
00c33482bb
Mismatch in probe platform_set_drvdata set's and method's that call
dev_get_platdata will result in "Unable to handle kernel NULL pointer
dereference", let's use according method for getting driver data after
platform_set_drvdata.
8<--- cut here ---
Unable to handle kernel NULL pointer dereference at virtual address 00000000
pgd = (ptrval)
[00000000] *pgd=00000000
Internal error: Oops: 5 [#1] ARM
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Not tainted 5.9.10-00003-g723e101e0037-dirty #4
Hardware name: Technologic Systems TS-72xx SBC
PC is at ep93xx_rtc_read_time+0xc/0x2c
LR is at __rtc_read_time+0x4c/0x8c
[...]
[<c02b01c8>] (ep93xx_rtc_read_time) from [<c02ac38c>] (__rtc_read_time+0x4c/0x8c)
[<c02ac38c>] (__rtc_read_time) from [<c02ac3f8>] (rtc_read_time+0x2c/0x4c)
[<c02ac3f8>] (rtc_read_time) from [<c02acc54>] (__rtc_read_alarm+0x28/0x358)
[<c02acc54>] (__rtc_read_alarm) from [<c02abd80>] (__rtc_register_device+0x124/0x2ec)
[<c02abd80>] (__rtc_register_device) from [<c02b028c>] (ep93xx_rtc_probe+0xa4/0xac)
[<c02b028c>] (ep93xx_rtc_probe) from [<c026424c>] (platform_drv_probe+0x24/0x5c)
[<c026424c>] (platform_drv_probe) from [<c0262918>] (really_probe+0x218/0x374)
[<c0262918>] (really_probe) from [<c0262da0>] (device_driver_attach+0x44/0x60)
[<c0262da0>] (device_driver_attach) from [<c0262e70>] (__driver_attach+0xb4/0xc0)
[<c0262e70>] (__driver_attach) from [<c0260d44>] (bus_for_each_dev+0x68/0xac)
[<c0260d44>] (bus_for_each_dev) from [<c026223c>] (driver_attach+0x18/0x24)
[<c026223c>] (driver_attach) from [<c0261dd8>] (bus_add_driver+0x150/0x1b4)
[<c0261dd8>] (bus_add_driver) from [<c026342c>] (driver_register+0xb0/0xf4)
[<c026342c>] (driver_register) from [<c0264210>] (__platform_driver_register+0x30/0x48)
[<c0264210>] (__platform_driver_register) from [<c04cb9ac>] (ep93xx_rtc_driver_init+0x10/0x1c)
[<c04cb9ac>] (ep93xx_rtc_driver_init) from [<c000973c>] (do_one_initcall+0x7c/0x1c0)
[<c000973c>] (do_one_initcall) from [<c04b9ecc>] (kernel_init_freeable+0x168/0x1ac)
[<c04b9ecc>] (kernel_init_freeable) from [<c03b2228>] (kernel_init+0x8/0xf4)
[<c03b2228>] (kernel_init) from [<c00082c0>] (ret_from_fork+0x14/0x34)
Exception stack(0xc441dfb0 to 0xc441dff8)
dfa0: 00000000 00000000 00000000 00000000
dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
dfe0: 00000000 00000000 00000000 00000000 00000013 00000000
Code: e12fff1e e92d4010 e590303c e1a02001 (e5933000)
---[ end trace c914d6030eaa95c8 ]---
Fixes: b809d192eb
("rtc: ep93xx: stop setting platform_data")
Signed-off-by: Nikita Shubin <nikita.shubin@maquefel.me>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20201201095507.10317-1-nikita.shubin@maquefel.me
164 lines
4.0 KiB
C
164 lines
4.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* A driver for the RTC embedded in the Cirrus Logic EP93XX processors
|
|
* Copyright (c) 2006 Tower Technologies
|
|
*
|
|
* Author: Alessandro Zummo <a.zummo@towertech.it>
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/rtc.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/io.h>
|
|
#include <linux/gfp.h>
|
|
|
|
#define EP93XX_RTC_DATA 0x000
|
|
#define EP93XX_RTC_MATCH 0x004
|
|
#define EP93XX_RTC_STATUS 0x008
|
|
#define EP93XX_RTC_STATUS_INTR BIT(0)
|
|
#define EP93XX_RTC_LOAD 0x00C
|
|
#define EP93XX_RTC_CONTROL 0x010
|
|
#define EP93XX_RTC_CONTROL_MIE BIT(0)
|
|
#define EP93XX_RTC_SWCOMP 0x108
|
|
#define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
|
|
#define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
|
|
#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
|
|
#define EP93XX_RTC_SWCOMP_INT_SHIFT 0
|
|
|
|
struct ep93xx_rtc {
|
|
void __iomem *mmio_base;
|
|
struct rtc_device *rtc;
|
|
};
|
|
|
|
static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
|
|
unsigned short *delete)
|
|
{
|
|
struct ep93xx_rtc *ep93xx_rtc = dev_get_drvdata(dev);
|
|
unsigned long comp;
|
|
|
|
comp = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP);
|
|
|
|
if (preload)
|
|
*preload = (comp & EP93XX_RTC_SWCOMP_INT_MASK)
|
|
>> EP93XX_RTC_SWCOMP_INT_SHIFT;
|
|
|
|
if (delete)
|
|
*delete = (comp & EP93XX_RTC_SWCOMP_DEL_MASK)
|
|
>> EP93XX_RTC_SWCOMP_DEL_SHIFT;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
|
{
|
|
struct ep93xx_rtc *ep93xx_rtc = dev_get_drvdata(dev);
|
|
unsigned long time;
|
|
|
|
time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
|
|
|
|
rtc_time64_to_tm(time, tm);
|
|
return 0;
|
|
}
|
|
|
|
static int ep93xx_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
|
{
|
|
struct ep93xx_rtc *ep93xx_rtc = dev_get_drvdata(dev);
|
|
unsigned long secs = rtc_tm_to_time64(tm);
|
|
|
|
writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
|
|
return 0;
|
|
}
|
|
|
|
static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
|
|
{
|
|
unsigned short preload, delete;
|
|
|
|
ep93xx_rtc_get_swcomp(dev, &preload, &delete);
|
|
|
|
seq_printf(seq, "preload\t\t: %d\n", preload);
|
|
seq_printf(seq, "delete\t\t: %d\n", delete);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct rtc_class_ops ep93xx_rtc_ops = {
|
|
.read_time = ep93xx_rtc_read_time,
|
|
.set_time = ep93xx_rtc_set_time,
|
|
.proc = ep93xx_rtc_proc,
|
|
};
|
|
|
|
static ssize_t comp_preload_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
unsigned short preload;
|
|
|
|
ep93xx_rtc_get_swcomp(dev->parent, &preload, NULL);
|
|
|
|
return sprintf(buf, "%d\n", preload);
|
|
}
|
|
static DEVICE_ATTR_RO(comp_preload);
|
|
|
|
static ssize_t comp_delete_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
unsigned short delete;
|
|
|
|
ep93xx_rtc_get_swcomp(dev->parent, NULL, &delete);
|
|
|
|
return sprintf(buf, "%d\n", delete);
|
|
}
|
|
static DEVICE_ATTR_RO(comp_delete);
|
|
|
|
static struct attribute *ep93xx_rtc_attrs[] = {
|
|
&dev_attr_comp_preload.attr,
|
|
&dev_attr_comp_delete.attr,
|
|
NULL
|
|
};
|
|
|
|
static const struct attribute_group ep93xx_rtc_sysfs_files = {
|
|
.attrs = ep93xx_rtc_attrs,
|
|
};
|
|
|
|
static int ep93xx_rtc_probe(struct platform_device *pdev)
|
|
{
|
|
struct ep93xx_rtc *ep93xx_rtc;
|
|
int err;
|
|
|
|
ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL);
|
|
if (!ep93xx_rtc)
|
|
return -ENOMEM;
|
|
|
|
ep93xx_rtc->mmio_base = devm_platform_ioremap_resource(pdev, 0);
|
|
if (IS_ERR(ep93xx_rtc->mmio_base))
|
|
return PTR_ERR(ep93xx_rtc->mmio_base);
|
|
|
|
platform_set_drvdata(pdev, ep93xx_rtc);
|
|
|
|
ep93xx_rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
|
|
if (IS_ERR(ep93xx_rtc->rtc))
|
|
return PTR_ERR(ep93xx_rtc->rtc);
|
|
|
|
ep93xx_rtc->rtc->ops = &ep93xx_rtc_ops;
|
|
ep93xx_rtc->rtc->range_max = U32_MAX;
|
|
|
|
err = rtc_add_group(ep93xx_rtc->rtc, &ep93xx_rtc_sysfs_files);
|
|
if (err)
|
|
return err;
|
|
|
|
return devm_rtc_register_device(ep93xx_rtc->rtc);
|
|
}
|
|
|
|
static struct platform_driver ep93xx_rtc_driver = {
|
|
.driver = {
|
|
.name = "ep93xx-rtc",
|
|
},
|
|
.probe = ep93xx_rtc_probe,
|
|
};
|
|
|
|
module_platform_driver(ep93xx_rtc_driver);
|
|
|
|
MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
|
|
MODULE_DESCRIPTION("EP93XX RTC driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:ep93xx-rtc");
|