diff mbox series

[v3,03/11] tty: serdev: Add flag buffer aware receive_buf_fp()

Message ID 20240502182804.145926-4-christoph.fritz@hexdev.de (mailing list archive)
State Superseded
Headers show
Series LIN Bus support for Linux | expand

Commit Message

Christoph Fritz May 2, 2024, 6:27 p.m. UTC
This patch introduces an additional receive buffer callback variation
besides the already existing receive_buf(). This new callback function
also passes the flag buffer (TTY_NORMAL, TTY_BREAK, and friends).

If defined, this function gets prioritized and called instead of the
standard receive_buf().

An alternative approach could have been to enhance the receive_buf()
function and update all drivers that use it.

Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
---
 drivers/tty/serdev/serdev-ttyport.c |  2 +-
 include/linux/serdev.h              | 17 ++++++++++++++---
 2 files changed, 15 insertions(+), 4 deletions(-)

Comments

Greg KH May 4, 2024, 4 p.m. UTC | #1
On Thu, May 02, 2024 at 08:27:56PM +0200, Christoph Fritz wrote:
> This patch introduces an additional receive buffer callback variation
> besides the already existing receive_buf(). This new callback function
> also passes the flag buffer (TTY_NORMAL, TTY_BREAK, and friends).
> 
> If defined, this function gets prioritized and called instead of the
> standard receive_buf().
> 
> An alternative approach could have been to enhance the receive_buf()
> function and update all drivers that use it.

Please, let's do that instead of adding random letters at the end of a
function pointer :)

> Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> ---
>  drivers/tty/serdev/serdev-ttyport.c |  2 +-
>  include/linux/serdev.h              | 17 ++++++++++++++---
>  2 files changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
> index 3d7ae7fa50186..bb47691afdb21 100644
> --- a/drivers/tty/serdev/serdev-ttyport.c
> +++ b/drivers/tty/serdev/serdev-ttyport.c
> @@ -32,7 +32,7 @@ static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp,
>  	if (!test_bit(SERPORT_ACTIVE, &serport->flags))
>  		return 0;
>  
> -	ret = serdev_controller_receive_buf(ctrl, cp, count);
> +	ret = serdev_controller_receive_buf(ctrl, cp, fp, count);
>  
>  	dev_WARN_ONCE(&ctrl->dev, ret > count,
>  				"receive_buf returns %zu (count = %zu)\n",
> diff --git a/include/linux/serdev.h b/include/linux/serdev.h
> index ff78efc1f60df..c6ef5a8988e07 100644
> --- a/include/linux/serdev.h
> +++ b/include/linux/serdev.h
> @@ -23,11 +23,17 @@ struct serdev_device;
>   * struct serdev_device_ops - Callback operations for a serdev device
>   * @receive_buf:	Function called with data received from device;
>   *			returns number of bytes accepted; may sleep.
> + * @receive_buf_fp:	Function called with data and flag buffer received
> + *			from device; If defined, this function gets called
> + *			instead of @receive_buf;
> + *			returns number of bytes accepted; may sleep.

I don't remember waht "fp" means here, and you don't document it, so
let's just have one recieve_buf() callback please.

thanks,

greg k-h
Christoph Fritz May 8, 2024, 8:48 a.m. UTC | #2
On Sat, 2024-05-04 at 18:00 +0200, Greg Kroah-Hartman wrote:
> On Thu, May 02, 2024 at 08:27:56PM +0200, Christoph Fritz wrote:
> > This patch introduces an additional receive buffer callback variation
> > besides the already existing receive_buf(). This new callback function
> > also passes the flag buffer (TTY_NORMAL, TTY_BREAK, and friends).
> > 
> > If defined, this function gets prioritized and called instead of the
> > standard receive_buf().
> > 
> > An alternative approach could have been to enhance the receive_buf()
> > function and update all drivers that use it.
> 
> Please, let's do that instead of adding random letters at the end of a
> function pointer :)

:) sure

> 
> > Signed-off-by: Christoph Fritz <christoph.fritz@hexdev.de>
> > ---
> >  drivers/tty/serdev/serdev-ttyport.c |  2 +-
> >  include/linux/serdev.h              | 17 ++++++++++++++---
> >  2 files changed, 15 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
> > index 3d7ae7fa50186..bb47691afdb21 100644
> > --- a/drivers/tty/serdev/serdev-ttyport.c
> > +++ b/drivers/tty/serdev/serdev-ttyport.c
> > @@ -32,7 +32,7 @@ static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp,
> >  	if (!test_bit(SERPORT_ACTIVE, &serport->flags))
> >  		return 0;
> >  
> > -	ret = serdev_controller_receive_buf(ctrl, cp, count);
> > +	ret = serdev_controller_receive_buf(ctrl, cp, fp, count);
> >  
> >  	dev_WARN_ONCE(&ctrl->dev, ret > count,
> >  				"receive_buf returns %zu (count = %zu)\n",
> > diff --git a/include/linux/serdev.h b/include/linux/serdev.h
> > index ff78efc1f60df..c6ef5a8988e07 100644
> > --- a/include/linux/serdev.h
> > +++ b/include/linux/serdev.h
> > @@ -23,11 +23,17 @@ struct serdev_device;
> >   * struct serdev_device_ops - Callback operations for a serdev device
> >   * @receive_buf:	Function called with data received from device;
> >   *			returns number of bytes accepted; may sleep.
> > + * @receive_buf_fp:	Function called with data and flag buffer received
> > + *			from device; If defined, this function gets called
> > + *			instead of @receive_buf;
> > + *			returns number of bytes accepted; may sleep.
> 
> I don't remember waht "fp" means here, and you don't document it, so
> let's just have one recieve_buf() callback please.

OK, that is a great opportunity for me to use Coccinelle. In the
upcoming revision v4 I'll add the "flag buffer pointer" treewide, then
named "flags".

thanks
  -- Christoph
diff mbox series

Patch

diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
index 3d7ae7fa50186..bb47691afdb21 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -32,7 +32,7 @@  static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp,
 	if (!test_bit(SERPORT_ACTIVE, &serport->flags))
 		return 0;
 
-	ret = serdev_controller_receive_buf(ctrl, cp, count);
+	ret = serdev_controller_receive_buf(ctrl, cp, fp, count);
 
 	dev_WARN_ONCE(&ctrl->dev, ret > count,
 				"receive_buf returns %zu (count = %zu)\n",
diff --git a/include/linux/serdev.h b/include/linux/serdev.h
index ff78efc1f60df..c6ef5a8988e07 100644
--- a/include/linux/serdev.h
+++ b/include/linux/serdev.h
@@ -23,11 +23,17 @@  struct serdev_device;
  * struct serdev_device_ops - Callback operations for a serdev device
  * @receive_buf:	Function called with data received from device;
  *			returns number of bytes accepted; may sleep.
+ * @receive_buf_fp:	Function called with data and flag buffer received
+ *			from device; If defined, this function gets called
+ *			instead of @receive_buf;
+ *			returns number of bytes accepted; may sleep.
  * @write_wakeup:	Function called when ready to transmit more data; must
  *			not sleep.
  */
 struct serdev_device_ops {
 	size_t (*receive_buf)(struct serdev_device *, const u8 *, size_t);
+	ssize_t (*receive_buf_fp)(struct serdev_device *, const u8 *,
+				  const u8 *, size_t);
 	void (*write_wakeup)(struct serdev_device *);
 };
 
@@ -186,15 +192,20 @@  static inline void serdev_controller_write_wakeup(struct serdev_controller *ctrl
 }
 
 static inline size_t serdev_controller_receive_buf(struct serdev_controller *ctrl,
-						   const u8 *data,
+						   const u8 *data, const u8 *fp,
 						   size_t count)
 {
 	struct serdev_device *serdev = ctrl->serdev;
 
-	if (!serdev || !serdev->ops->receive_buf)
+	if (!serdev || !serdev->ops)
 		return 0;
 
-	return serdev->ops->receive_buf(serdev, data, count);
+	if (serdev->ops->receive_buf_fp)
+		return serdev->ops->receive_buf_fp(serdev, data, fp, count);
+	else if (serdev->ops->receive_buf)
+		return serdev->ops->receive_buf(serdev, data, count);
+
+	return 0;
 }
 
 #if IS_ENABLED(CONFIG_SERIAL_DEV_BUS)