diff mbox series

[08/18] ledtrig-blkdev: Add miscellaneous helper functions

Message ID 20210903204548.2745354-9-arequipeno@gmail.com
State New
Headers show
Series Introduce block device LED trigger | expand

Commit Message

Ian Pilcher Sept. 3, 2021, 8:45 p.m. UTC
Add blkdev_skip_space() and blkdev_find_space() for parsing writes to
sysfs attributes

Add blkdev_read_mode() and blkdev_write_mode() LED comparison helpers

Signed-off-by: Ian Pilcher <arequipeno@gmail.com>
---
 drivers/leds/trigger/ledtrig-blkdev.c | 44 +++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Comments

Greg Kroah-Hartman Sept. 4, 2021, 6 a.m. UTC | #1
On Fri, Sep 03, 2021 at 03:45:38PM -0500, Ian Pilcher wrote:
> Add blkdev_skip_space() and blkdev_find_space() for parsing writes to

> sysfs attributes

> 

> Add blkdev_read_mode() and blkdev_write_mode() LED comparison helpers

> 

> Signed-off-by: Ian Pilcher <arequipeno@gmail.com>

> ---

>  drivers/leds/trigger/ledtrig-blkdev.c | 44 +++++++++++++++++++++++++++

>  1 file changed, 44 insertions(+)

> 

> diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c

> index db8326874400..1f319529c3be 100644

> --- a/drivers/leds/trigger/ledtrig-blkdev.c

> +++ b/drivers/leds/trigger/ledtrig-blkdev.c

> @@ -6,6 +6,7 @@

>   *	Copyright 2021 Ian Pilcher <arequipeno@gmail.com>

>   */

>  

> +#include <linux/ctype.h>

>  #include <linux/module.h>

>  

>  #include "ledtrig-blkdev.h"

> @@ -66,3 +67,46 @@ static unsigned int ledtrig_blkdev_count;

>  

>  /* How often to check for drive activity - in jiffies */

>  static unsigned int ledtrig_blkdev_interval;

> +

> +

> +/*

> + *

> + *	Miscellaneous helper functions

> + *

> + */

> +

> +/*

> + * Returns a pointer to the first non-whitespace character in s

> + * (or a pointer to the terminating null).

> + */

> +static const char *blkdev_skip_space(const char *s)

> +{

> +	while (*s != 0 && isspace(*s))

> +		++s;

> +

> +	return s;

> +}

> +

> +/*

> + * Returns a pointer to the first whitespace character in s (or a pointer to the

> + * terminating null), which is effectively a pointer to the position *after* the

> + * last character in the non-whitespace token at the beginning of s.  (s is

> + * expected to be the result of a previous call to blkdev_skip_space()).

> + */

> +static const char *blkdev_find_space(const char *s)

> +{

> +	while (*s != 0 && !isspace(*s))

> +		++s;

> +

> +	return s;

> +}


Why are block devices odd and need to have spaces found in their names?

And are you sure we do not already have string functions that do this?

thanks,

greg k-h
Ian Pilcher Sept. 4, 2021, 10:43 p.m. UTC | #2
On 9/4/21 1:00 AM, Greg KH wrote:
> Why are block devices odd and need to have spaces found in their names?


They aren't.  The functions are used to identify the block device names
within the buffer that is passed to attribute store functions, which may
contain whitespace.

> And are you sure we do not already have string functions that do this?


I did look a bit.  I can't be sure, but I didn't find anything similar.

-- 
========================================================================
                  In Soviet Russia, Google searches you!
========================================================================
diff mbox series

Patch

diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c
index db8326874400..1f319529c3be 100644
--- a/drivers/leds/trigger/ledtrig-blkdev.c
+++ b/drivers/leds/trigger/ledtrig-blkdev.c
@@ -6,6 +6,7 @@ 
  *	Copyright 2021 Ian Pilcher <arequipeno@gmail.com>
  */
 
+#include <linux/ctype.h>
 #include <linux/module.h>
 
 #include "ledtrig-blkdev.h"
@@ -66,3 +67,46 @@  static unsigned int ledtrig_blkdev_count;
 
 /* How often to check for drive activity - in jiffies */
 static unsigned int ledtrig_blkdev_interval;
+
+
+/*
+ *
+ *	Miscellaneous helper functions
+ *
+ */
+
+/*
+ * Returns a pointer to the first non-whitespace character in s
+ * (or a pointer to the terminating null).
+ */
+static const char *blkdev_skip_space(const char *s)
+{
+	while (*s != 0 && isspace(*s))
+		++s;
+
+	return s;
+}
+
+/*
+ * Returns a pointer to the first whitespace character in s (or a pointer to the
+ * terminating null), which is effectively a pointer to the position *after* the
+ * last character in the non-whitespace token at the beginning of s.  (s is
+ * expected to be the result of a previous call to blkdev_skip_space()).
+ */
+static const char *blkdev_find_space(const char *s)
+{
+	while (*s != 0 && !isspace(*s))
+		++s;
+
+	return s;
+}
+
+static bool blkdev_read_mode(const enum ledtrig_blkdev_mode mode)
+{
+	return mode != LEDTRIG_BLKDEV_MODE_WO;
+}
+
+static bool blkdev_write_mode(const enum ledtrig_blkdev_mode mode)
+{
+	return mode != LEDTRIG_BLKDEV_MODE_RO;
+}