rtc: mips: default to rtc-cmos on mips
Subsystems (4)
Arnd Bergmann
maintainerPATCH 2/2 rtc: move compat_ioctl handling into rtc-dev.c
In reply to Arnd BergmannWe no longer need the rtc compat handling to be in common code, now that all drivers are either moved to the rtc-class framework, or (rarely) exist in drivers/char for architectures without compat mode (m68k, alpha and ia64, respectively).
I checked the list of ioctl commands in drivers, and the ones that are not already handled are all compatible, again with the one exception of m68k driver, which implements RTC_PLL_GET and RTC_PLL_SET, but has no compat mode.
--- drivers/rtc/rtc-dev.c | 50 +++++++++++++++++++++++++++++++++++++++ fs/compat_ioctl.c | 54 ------------------------------------------- 2 files changed, 50 insertions(+), 54 deletions(-)
drivers/rtc/rtc-dev.c +50 -0
@@ -13,6 +13,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/compat.h> #include <linux/module.h> #include <linux/rtc.h> #include <linux/sched/signal.h>
@@ -405,6 +406,52 @@ static long rtc_dev_ioctl(struct file *file,return err; } +#ifdef CONFIG_COMPAT +#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t) +#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t) +#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t) +#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t) + +static long rtc_dev_compat_ioctl (struct file *file,unsigned cmd,unsigned long arg) +{ +unsigned long __user *valp; +compat_ulong_t __user *argp =compat_ptr (arg); +unsigned long val; +int ret; + +switch (cmd) { +/* pointer to 'long' needs translation. */ +case RTC_IRQP_READ32 : +case RTC_EPOCH_READ32 : { + valp =compat_alloc_user_space (sizeof (*valp)); +if (valp ==NULL ) +return -EFAULT ; + ret =rtc_dev_ioctl (file, (cmd ==RTC_IRQP_READ32 ) ? +RTC_IRQP_READ :RTC_EPOCH_READ , + (unsigned long )valp); +if (ret) +return ret; +if (get_user (val, valp) ||put_user (val, argp)) +return -EFAULT ; +return 0 ; + } + +/* arguments are compatible, command number is not */ +case RTC_IRQP_SET32 : +return rtc_dev_ioctl (file,RTC_IRQP_SET , arg); +case RTC_EPOCH_SET32 : +return rtc_dev_ioctl (file,RTC_EPOCH_SET , arg); + } + +/* +* all other rtc ioctls are compatible, or only +* exist on architectures without compat mode +*/ + +return rtc_dev_ioctl (file, cmd, (unsigned long )argp); +} +#endif +static int rtc_dev_fasync (int fd,struct file *file,int on) {struct rtc_device *rtc = file->private_data;
@@ -439,6 +486,9 @@ static const struct file_operations rtc_dev_fops = { .read = rtc_dev_read, .poll = rtc_dev_poll, .unlocked_ioctl = rtc_dev_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = rtc_dev_compat_ioctl, +#endif .open = rtc_dev_open, .release = rtc_dev_release, .fasync = rtc_dev_fasync,
fs/compat_ioctl.c +0 -54
78 lines not on this page · raw message
Signature · 1 line
2.18.0
Arnd Bergmann
maintainerPATCH 1/2 rtc: mips: default to rtc-cmos on mips
The old rtc driver is getting in the way of some compat_ioctl simplification. Looking up the loongson64 git history, it seems that everyone uses the more modern but compatible RTC_CMOS driver anyway, so let's remove the special case for loongson64.
--- arch/mips/Kconfig | 2 +- drivers/char/Kconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/mips/Kconfig +1 -1
@@ -75,7 +75,7 @@ config MIPS select MODULES_USE_ELF_RELA if MODULES && 64BIT select MODULES_USE_ELF_REL if MODULES select PERF_USE_VMALLOC - select RTC_LIB if !MACH_LOONGSON64 + select RTC_LIB select SYSCTL_EXCEPTION_TRACE select VIRT_TO_BUS
drivers/char/Kconfig +1 -1
@@ -268,7 +268,7 @@ if RTC_LIB=n config RTC tristate "Enhanced Real Time Clock Support (legacy PC RTC driver)" - depends on ALPHA || (MIPS && MACH_LOONGSON64) + depends on ALPHA ---help--- If you say Y here and create a character special file /dev/rtc with major number 10 and minor number 135 using mknod ("man mknod"), you
Signature · 1 line
2.18.0
Al Viro
maintainerRe: [PATCH 2/2] rtc: move compat_ioctl handling into rtc-dev.c
In reply to Arnd BergmannQuoted 17 lines · Arnd Bergmann
drivers/rtc/rtc-dev.c +17
-0+#ifdef CONFIG_COMPAT +#define RTC_IRQP_READ32 _IOR('p', 0x0b, compat_ulong_t) +#define RTC_IRQP_SET32 _IOW('p', 0x0c, compat_ulong_t) +#define RTC_EPOCH_READ32 _IOR('p', 0x0d, compat_ulong_t) +#define RTC_EPOCH_SET32 _IOW('p', 0x0e, compat_ulong_t) + +static long rtc_dev_compat_ioctl (struct file *file,unsigned cmd,unsigned long arg) +{ +unsigned long __user *valp; +compat_ulong_t __user *argp =compat_ptr (arg); +unsigned long val; +int ret; + +switch (cmd) { +/* pointer to 'long' needs translation. */ +case RTC_IRQP_READ32 : +case RTC_EPOCH_READ32 : {
drivers/rtc/rtc-dev.c static long rtc_dev_ioctl(struct file *file, · line 435
Quoted 10 lines
drivers/rtc/rtc-dev.c +10
-0+ valp =compat_alloc_user_space (sizeof (*valp)); +if (valp ==NULL ) +return -EFAULT ; + ret =rtc_dev_ioctl (file, (cmd ==RTC_IRQP_READ32 ) ? +RTC_IRQP_READ :RTC_EPOCH_READ , + (unsigned long )valp); +if (ret) +return ret; +if (get_user (val, valp) ||put_user (val, argp)) +return -EFAULT ;
No. With the side of Hell, No. This is bloody ridiculous - take a look
at rtc_dev_ioctl(). Seriously. Relevant bits:
struct rtc_device *rtc = file->private_data;
const struct rtc_class_ops *ops = rtc->ops;
struct rtc_time tm;
struct rtc_wkalrm alarm;
void __user *uarg = (void __user *) arg;
err = mutex_lock_interruptible(&rtc->ops_lock);
if (err)
return err;
err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
mutex_unlock(&rtc->ops_lock);
return err;That's RTC_IRQP_READ. IOW, all that song and dance starting with compat_alloc_user_space() is just a way to get to rtc->irq_freq value.
RTC_EPOCH_READ is in the bowels of individual implementations, but it's otherwise very similar; add a method returning the damn thing (e.g. rtc->ops->get_epoch(rtc)) and lift its call into rtc_dev_ioctl(), then this nonsense will go away as well.
drivers/rtc/rtc-dev.c static long rtc_dev_ioctl(struct file *file, · line 441
Quoted 6 lines
drivers/rtc/rtc-dev.c +6
-0+return 0 ; + } + +/* arguments are compatible, command number is not */ +case RTC_IRQP_SET32 : +return rtc_dev_ioctl (file,RTC_IRQP_SET , arg);
ITYM
cmd = RTC_IRQP_SET; break;
drivers/rtc/rtc-dev.c static long rtc_dev_ioctl(struct file *file, · line 442
Quoted 1 line
drivers/rtc/rtc-dev.c +1
-0+case RTC_EPOCH_SET32 :
... and
cmd = RTC_EPOCH_SET; break;
here.
drivers/rtc/rtc-dev.c static long rtc_dev_ioctl(struct file *file, · line 452
Quoted 10 lines
drivers/rtc/rtc-dev.c +10
-0+return rtc_dev_ioctl (file,RTC_EPOCH_SET , arg); + } + +/* +* all other rtc ioctls are compatible, or only +* exist on architectures without compat mode +*/ + +return rtc_dev_ioctl (file, cmd, (unsigned long )argp); +}
compat_alloc_user_space() is usually papering over bogosities like that; if you are moving something out to individual drivers, it's always a red flag - most of the time it'll turn out to be pointless.
Arnd Bergmann
maintainerRe: [PATCH 2/2] rtc: move compat_ioctl handling into rtc-dev.c
Quoted 32 lines · Al Viro
Review
Quoted 12 lines · Arnd Bergmann
(quoted diff) +12
-0+ case RTC_IRQP_READ32: + case RTC_EPOCH_READ32: { + valp = compat_alloc_user_space(sizeof(*valp)); + if (valp == NULL) + return -EFAULT; + ret = rtc_dev_ioctl(file, (cmd == RTC_IRQP_READ32) ? + RTC_IRQP_READ : RTC_EPOCH_READ, + (unsigned long)valp); + if (ret) + return ret; + if (get_user(val, valp) || put_user(val, argp)) + return -EFAULT;No. With the side of Hell, No. This is bloody ridiculous - take a look
atrtc_dev_ioctl(). Seriously. Relevant bits:struct rtc_device *rtc = file->private_data; const struct rtc_class_ops *ops = rtc->ops; struct rtc_time tm; struct rtc_wkalrm alarm; void __user *uarg = (void __user *) arg; err = mutex_lock_interruptible(&rtc->ops_lock); if (err) return err; err = put_user(rtc->irq_freq, (unsigned long __user *)uarg); mutex_unlock(&rtc->ops_lock); return err;
Quoted 7 lines
That's
RTC_IRQP_READ. IOW, all that song and dance starting withcompat_alloc_user_space()is just a way to get tortc->irq_freqvalue.
RTC_EPOCH_READis in the bowels of individual implementations, but it's otherwise very similar; add a method returning the damn thing (e.g.rtc->ops->get_epoch(rtc)) and lift its call intortc_dev_ioctl(), then this nonsense will go away as well.
Okay. I was basically trying to do one step of moving the code in a more appropriate place without changing it much. The problem I see with a get_epoch() callback is that we don't actually want more drivers to implement it. At the moment there is only one (vr41xx), so how about just moving the compat epoch handling there and completely leaving it outside of the common rtc-dev implementation?
drivers/rtc/rtc-vr41xx.c +1 -0
@@ -17,6 +17,7 @@* along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <linux/compat.h> #include <linux/err.h> #include <linux/fs.h> #include <linux/init.h>
@@ -195,6 +196,11 @@ static int vr41xx_rtc_ioctl(struct device *dev,
unsigned int cmd, unsigned long
switch (cmd) {
case RTC_EPOCH_READ:
return put_user(epoch, (unsigned long __user *)arg);+#ifdef CONFIG_COMPAT
+ case RTC_EPOCH_READ32:
+ return put_user(epoch, (unsigned int __user *)arg);
+ case RTC_EPOCH_SET32:
+#endif
case RTC_EPOCH_SET:
/* Doesn't support before 1900 */Quoted 6 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ return 0; + } + + /* arguments are compatible, command number is not */ + case RTC_IRQP_SET32: + return rtc_dev_ioctl(file, RTC_IRQP_SET, arg);
Quoted 8 lines
ITYM
cmd = RTC_IRQP_SET; break;Quoted 1 line
+ case
RTC_EPOCH_SET32:... and
cmd = RTC_EPOCH_SET; break;here.
Just to clarify: do you mean I copied a bug from the old code, or are you objecting to the coding style?
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+ return rtc_dev_ioctl(file, RTC_EPOCH_SET, arg); + } + + /* + * all other rtc ioctls are compatible, or only + * exist on architectures without compat mode
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ */ + + return rtc_dev_ioctl(file, cmd, (unsigned long)argp); +}
compat_alloc_user_space()is usually papering over bogosities like that; if you are moving something out to individual drivers, it's always a red flag - most of the time it'll turn out to be pointless.
Absolutely agreed. Eliminating compat_alloc_user_space() was a bit lower on my priority list than killing off do_ioctl_trans() (which is already fairly low at the bottom), but I've adjusted that and will send an update.
I have a couple more patches for do_ioctl_trans() that started out as a side product of my y2038 patches, I'll make sure to do it the same way for any others. SG_GET_REQUEST_TABLE was the only other command for which I chose to keep compat_alloc_user_space() after my attempt to kill it ended up in way more complexity, but I can also revisit that, or maybe drop that patch until I get motivated to also tackle SG_IO.
Arnd