lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210819025053.222710-5-arequipeno@gmail.com>
Date:   Wed, 18 Aug 2021 21:50:39 -0500
From:   Ian Pilcher <arequipeno@...il.com>
To:     linux-block@...r.kernel.org, linux-leds@...r.kernel.org
Cc:     axboe@...nel.dk, pavel@....cz, kabel@...nel.org,
        linux-kernel@...r.kernel.org, kernelnewbies@...nelnewbies.org
Subject: [RFC PATCH v3 04/18] ledtrig-blkdev: Add misc. helper functions to blkdev LED trigger

Add various helper functions to the block device LED trigger:

  * blkdev_mkdir() - create a sysfs directory (and don't swallow error
    codes)

  * blkdev_streq(), blkdev_skip_space() & blkdev_find_space() - for
    parsing writes to sysfs attributes

  * blkdev_read_mode() & blkdev_write_mode() - LED mode activity type
    helpers

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

diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c
index 28ccbd7946ba..fcae7ce63b92 100644
--- a/drivers/leds/trigger/ledtrig-blkdev.c
+++ b/drivers/leds/trigger/ledtrig-blkdev.c
@@ -6,6 +6,7 @@
  *	Copyright 2021 Ian Pilcher <arequipeno@...il.com>
  */
 
+#include <linux/ctype.h>
 #include <linux/leds.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
@@ -64,3 +65,76 @@ static unsigned int ledtrig_blkdev_count;
 
 /* How often to check for drive activity - in jiffies */
 static unsigned int ledtrig_blkdev_interval;
+
+
+/*
+ *
+ *	Miscellaneous helper functions
+ *
+ */
+
+/* Like kobject_create_and_add(), but doesn't swallow error codes */
+static struct kobject *blkdev_mkdir(const char *const name,
+				    struct kobject *const parent)
+{
+	struct kobject *dir;
+	int ret;
+
+	dir = kobject_create();
+	if (dir == NULL)
+		return ERR_PTR(-ENOMEM);
+
+	ret = kobject_add(dir, parent, "%s", name);
+	if (ret != 0) {
+		kobject_put(dir);
+		return ERR_PTR(ret);
+	}
+
+	return dir;
+}
+
+/*
+ * Compare a null-terminated C string with a non-null-terminated character
+ * sequence of a known length.  Returns true if equal, false if not.
+ */
+static bool blkdev_streq(const char *const cstr,
+			 const char *const cbuf, const size_t buf_len)
+{
+	return (strlen(cstr) == buf_len) && (memcmp(cstr, cbuf, buf_len) == 0);
+}
+
+/*
+ * 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;
+}
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ