Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp514100imm; Fri, 13 Jul 2018 01:17:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfToB3KPrd9762WS+wpiZopjQHWRdGSbNRNolGu4rxkwRWR4aViEdA8H2TOExJk84vWvegA X-Received: by 2002:a17:902:a716:: with SMTP id w22-v6mr5355710plq.271.1531469848638; Fri, 13 Jul 2018 01:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531469848; cv=none; d=google.com; s=arc-20160816; b=lioamPyfR88Prp1psmJ3dlXTV+zIml3FJPK+Gx5g2ba/t6fGjWX6ZpR6WnotXvhN/H phEIZ0lzHroNMb+MY/q4dOaXOwxQ7YPjyRd1Gkl4SdF6wc1oJgVvSyAF1EN0xJq8B1po u33qtPlqiFBGu9rl+pEI2jA5e3if6DnFcM1KZzzwlYkw+kr4OHLjQpXNuKbriFSk6fIQ cGKRhP/25/KcjeyMHxCxMqRVtLqi1GZ/C5+eGMTVDacqgl3N2g3MhNzOg+DwZEbYmihG SPQ29ooBL2+YnAGvWPb1Hx8lIrPOLkXS5HuaVK4FpghrNKb2IjegT3nXT/wpcKMK5lpD uZkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:arc-authentication-results; bh=YrpnWtnCz8KfU9ebUzG55XvmwG5do9qqAgrKLX+393s=; b=hDRpnTgFTB1rqUwJ2jXqvahLAhlvSzXSJu5d0q5M+vfv6+JxnAWWA5645dWXg6PIGf TCslQDcTDjP6Fu4jDWny4lSUw72zMUC6daVe1rDdG0EHGsVYKFLKCCSq7JDeZMvBS31F 1PillzBWk28EcallNtK6k4RaBznawTI6FUti7WdlKJphiFlK2i3G6pyJBq1qpe61/aYb OcaBTv5R+SHJ2XdbrenyqQu/jtAPTDHgHzZyZvHoYYkggGqgqtR4ci9zFYi5v5MHJcMn zwB9wlvGbxyIidTjXoB1+ugAsb0yCozVk39K9goeScMbW2q43etjW4T9cWkDcFvZneRz Awvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f132-v6si22387822pgc.20.2018.07.13.01.17.13; Fri, 13 Jul 2018 01:17:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731871AbeGMIaJ (ORCPT + 99 others); Fri, 13 Jul 2018 04:30:09 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46980 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729766AbeGMIaJ (ORCPT ); Fri, 13 Jul 2018 04:30:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EDB132C; Fri, 13 Jul 2018 08:16:34 +0000 (UTC) Date: Fri, 13 Jul 2018 10:16:32 +0200 From: Greg KH To: linux-arch@vger.kernel.org, alexandre.belloni@bootlin.com, arnd@arndb.de, richard.genoud@gmail.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, jslaby@suse.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 1/3] tty/serial_core: add ISO7816 infrastructure Message-ID: <20180713081632.GA3310@kroah.com> References: <20180711131638.12622-1-ludovic.desroches@microchip.com> <20180711131638.12622-2-ludovic.desroches@microchip.com> <20180712150229.GE22502@kroah.com> <20180713075648.ya2er5eip6uldl75@M43218.corp.atmel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180713075648.ya2er5eip6uldl75@M43218.corp.atmel.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 13, 2018 at 09:56:48AM +0200, Ludovic Desroches wrote: > On Thu, Jul 12, 2018 at 05:02:29PM +0200, Greg KH wrote: > > On Wed, Jul 11, 2018 at 03:16:36PM +0200, Ludovic Desroches wrote: > > > From: Nicolas Ferre > > > > > > Add the ISO7816 ioctl and associated accessors and data structure. > > > Drivers can then use this common implementation to handle ISO7816. > > > > > > Signed-off-by: Nicolas Ferre > > > [ludovic.desroches@microchip.com: squash and rebase, removal of gpios, checkpatch fixes] > > > Signed-off-by: Ludovic Desroches > > > --- > > > drivers/tty/serial/serial_core.c | 49 +++++++++++++++++++++++++++++++++++++++ > > > include/linux/serial_core.h | 3 +++ > > > include/uapi/asm-generic/ioctls.h | 2 ++ > > > include/uapi/linux/serial.h | 17 ++++++++++++++ > > > 4 files changed, 71 insertions(+) > > > > > > diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c > > > index 9c14a453f73c..c89ac59f6f8c 100644 > > > --- a/drivers/tty/serial/serial_core.c > > > +++ b/drivers/tty/serial/serial_core.c > > > @@ -1301,6 +1301,47 @@ static int uart_set_rs485_config(struct uart_port *port, > > > return 0; > > > } > > > > > > +static int uart_get_iso7816_config(struct uart_port *port, > > > + struct serial_iso7816 __user *iso7816) > > > +{ > > > + unsigned long flags; > > > + struct serial_iso7816 aux; > > > + > > > + spin_lock_irqsave(&port->lock, flags); > > > + aux = port->iso7816; > > > + spin_unlock_irqrestore(&port->lock, flags); > > > + > > > + if (copy_to_user(iso7816, &aux, sizeof(aux))) > > > + return -EFAULT; > > > + > > > + return 0; > > > +} > > > + > > > +static int uart_set_iso7816_config(struct uart_port *port, > > > + struct serial_iso7816 __user *iso7816_user) > > > +{ > > > + struct serial_iso7816 iso7816; > > > + int ret; > > > + unsigned long flags; > > > + > > > + if (!port->iso7816_config) > > > + return -ENOIOCTLCMD; > > > + > > > + if (copy_from_user(&iso7816, iso7816_user, sizeof(*iso7816_user))) > > > + return -EFAULT; > > > + > > > + spin_lock_irqsave(&port->lock, flags); > > > + ret = port->iso7816_config(port, &iso7816); > > > + spin_unlock_irqrestore(&port->lock, flags); > > > + if (ret) > > > + return ret; > > > + > > > + if (copy_to_user(iso7816_user, &port->iso7816, sizeof(port->iso7816))) > > > + return -EFAULT; > > > + > > > + return 0; > > > +} > > > + > > > /* > > > * Called via sys_ioctl. We can use spin_lock_irq() here. > > > */ > > > @@ -1385,6 +1426,14 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) > > > case TIOCSRS485: > > > ret = uart_set_rs485_config(uport, uarg); > > > break; > > > + > > > + case TIOCSISO7816: > > > + ret = uart_set_iso7816_config(state->uart_port, uarg); > > > + break; > > > + > > > + case TIOCGISO7816: > > > + ret = uart_get_iso7816_config(state->uart_port, uarg); > > > + break; > > > default: > > > if (uport->ops->ioctl) > > > ret = uport->ops->ioctl(uport, cmd, arg); > > > diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h > > > index 06ea4eeb09ab..d6e7747ffd46 100644 > > > --- a/include/linux/serial_core.h > > > +++ b/include/linux/serial_core.h > > > @@ -137,6 +137,8 @@ struct uart_port { > > > void (*handle_break)(struct uart_port *); > > > int (*rs485_config)(struct uart_port *, > > > struct serial_rs485 *rs485); > > > + int (*iso7816_config)(struct uart_port *, > > > + struct serial_iso7816 *iso7816); > > > unsigned int irq; /* irq number */ > > > unsigned long irqflags; /* irq flags */ > > > unsigned int uartclk; /* base uart clock */ > > > @@ -253,6 +255,7 @@ struct uart_port { > > > struct attribute_group *attr_group; /* port specific attributes */ > > > const struct attribute_group **tty_groups; /* all attributes (serial core use only) */ > > > struct serial_rs485 rs485; > > > + struct serial_iso7816 iso7816; > > > void *private_data; /* generic platform data pointer */ > > > }; > > > > > > diff --git a/include/uapi/asm-generic/ioctls.h b/include/uapi/asm-generic/ioctls.h > > > index 040651735662..0e5c79726c2d 100644 > > > --- a/include/uapi/asm-generic/ioctls.h > > > +++ b/include/uapi/asm-generic/ioctls.h > > > @@ -66,6 +66,8 @@ > > > #ifndef TIOCSRS485 > > > #define TIOCSRS485 0x542F > > > #endif > > > +#define TIOCGISO7816 0x5430 > > > +#define TIOCSISO7816 0x5431 > > > #define TIOCGPTN _IOR('T', 0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ > > > #define TIOCSPTLCK _IOW('T', 0x31, int) /* Lock/unlock Pty */ > > > #define TIOCGDEV _IOR('T', 0x32, unsigned int) /* Get primary device node of /dev/console */ > > > diff --git a/include/uapi/linux/serial.h b/include/uapi/linux/serial.h > > > index 3fdd0dee8b41..93eb3c496ff1 100644 > > > --- a/include/uapi/linux/serial.h > > > +++ b/include/uapi/linux/serial.h > > > @@ -132,4 +132,21 @@ struct serial_rs485 { > > > are a royal PITA .. */ > > > }; > > > > > > +/* > > > + * Serial interface for controlling ISO7816 settings on chips with suitable > > > + * support. Set with TIOCSISO7816 and get with TIOCGISO7816 if supported by > > > + * your platform. > > > + */ > > > +struct serial_iso7816 { > > > + __u32 flags; /* ISO7816 feature flags */ > > > +#define SER_ISO7816_ENABLED (1 << 0) > > > +#define SER_ISO7816_T_PARAM (0x0f << 4) > > > +#define SER_ISO7816_T(t) (((t) & 0x0f) << 4) > > > + __u32 tg; > > > + __u32 sc_fi; > > > + __u32 sc_di; > > > + __u32 clk; > > > + __u32 reserved[5]; > > > > You need to verify that reserved[] is all set to 0, otherwise people > > will put crud in there and you can never use it for anything in the > > future. > > Should I just verify or force it to 0? Verify please, and then abort if they are not set to 0. Otherwise if userspace puts odd stuff in there, and then later you decide to use it as new fields, that old code will start to do odd things. thanks, greg k-h