fbdev: imsttfb: Fix use after free bug in imsttfb_probe
[linux-block.git] / drivers / rtc / proc.c
CommitLineData
cdf7545a 1// SPDX-License-Identifier: GPL-2.0
728a2947
AZ
2/*
3 * RTC subsystem, proc interface
4 *
5 * Copyright (C) 2005-06 Tower Technologies
6 * Author: Alessandro Zummo <a.zummo@towertech.it>
7 *
8 * based on arch/arm/common/rtctime.c
cdf7545a 9 */
728a2947
AZ
10
11#include <linux/module.h>
12#include <linux/rtc.h>
13#include <linux/proc_fs.h>
14#include <linux/seq_file.h>
15
ab6a2d70
DB
16#include "rtc-core.h"
17
92589c98
KM
18#define NAME_SIZE 10
19
20#if defined(CONFIG_RTC_HCTOSYS_DEVICE)
21static bool is_rtc_hctosys(struct rtc_device *rtc)
22{
23 int size;
24 char name[NAME_SIZE];
25
54b90943
DC
26 size = snprintf(name, NAME_SIZE, "rtc%d", rtc->id);
27 if (size >= NAME_SIZE)
92589c98
KM
28 return false;
29
30 return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
31}
32#else
33static bool is_rtc_hctosys(struct rtc_device *rtc)
34{
35 return (rtc->id == 0);
36}
37#endif
ab6a2d70 38
728a2947
AZ
39static int rtc_proc_show(struct seq_file *seq, void *offset)
40{
41 int err;
ab6a2d70
DB
42 struct rtc_device *rtc = seq->private;
43 const struct rtc_class_ops *ops = rtc->ops;
728a2947
AZ
44 struct rtc_wkalrm alrm;
45 struct rtc_time tm;
46
ab6a2d70 47 err = rtc_read_time(rtc, &tm);
728a2947
AZ
48 if (err == 0) {
49 seq_printf(seq,
5548cbf7
AS
50 "rtc_time\t: %ptRt\n"
51 "rtc_date\t: %ptRd\n",
52 &tm, &tm);
728a2947
AZ
53 }
54
ab6a2d70 55 err = rtc_read_alarm(rtc, &alrm);
728a2947 56 if (err == 0) {
5548cbf7
AS
57 seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
58 seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
a2db8dfc 59 seq_printf(seq, "alarm_IRQ\t: %s\n",
606cc43c 60 alrm.enabled ? "yes" : "no");
728a2947 61 seq_printf(seq, "alrm_pending\t: %s\n",
606cc43c 62 alrm.pending ? "yes" : "no");
bca8521c 63 seq_printf(seq, "update IRQ enabled\t: %s\n",
606cc43c 64 (rtc->uie_rtctimer.enabled) ? "yes" : "no");
bca8521c 65 seq_printf(seq, "periodic IRQ enabled\t: %s\n",
606cc43c 66 (rtc->pie_enabled) ? "yes" : "no");
bca8521c 67 seq_printf(seq, "periodic IRQ frequency\t: %d\n",
606cc43c 68 rtc->irq_freq);
bca8521c 69 seq_printf(seq, "max user IRQ frequency\t: %d\n",
606cc43c 70 rtc->max_user_freq);
728a2947
AZ
71 }
72
adfb4341
AZ
73 seq_printf(seq, "24hr\t\t: yes\n");
74
728a2947 75 if (ops->proc)
cd966209 76 ops->proc(rtc->dev.parent, seq);
728a2947
AZ
77
78 return 0;
79}
80
7d9f99ec 81void rtc_proc_add_device(struct rtc_device *rtc)
728a2947 82{
92589c98 83 if (is_rtc_hctosys(rtc))
59cacb8d 84 proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
606cc43c 85 rtc);
728a2947
AZ
86}
87
7d9f99ec 88void rtc_proc_del_device(struct rtc_device *rtc)
728a2947 89{
92589c98 90 if (is_rtc_hctosys(rtc))
728a2947 91 remove_proc_entry("driver/rtc", NULL);
728a2947 92}