Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/clk Normalize clk name to prevent sysctl_createv fro...
details: https://anonhg.NetBSD.org/src/rev/ebb7d9ed3162
branches: trunk
changeset: 452752:ebb7d9ed3162
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Tue Jul 23 17:44:03 2019 +0000
description:
Normalize clk name to prevent sysctl_createv from failing
diffstat:
sys/dev/clk/clk.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diffs (78 lines):
diff -r d29fd0b00ceb -r ebb7d9ed3162 sys/dev/clk/clk.c
--- a/sys/dev/clk/clk.c Tue Jul 23 17:39:36 2019 +0000
+++ b/sys/dev/clk/clk.c Tue Jul 23 17:44:03 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clk.c,v 1.6 2019/01/30 01:20:47 jmcneill Exp $ */
+/* $NetBSD: clk.c,v 1.7 2019/07/23 17:44:03 jmcneill Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,10 +27,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clk.c,v 1.6 2019/01/30 01:20:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clk.c,v 1.7 2019/07/23 17:44:03 jmcneill Exp $");
#include <sys/param.h>
#include <sys/sysctl.h>
+#include <sys/kmem.h>
#include <dev/clk/clk.h>
#include <dev/clk/clk_backend.h>
@@ -135,11 +136,23 @@
return sysctl_lookup(SYSCTLFN_CALL(&node));
}
+static void
+clk_normalize_name(char *name)
+{
+ unsigned char *p;
+
+ for (p = (unsigned char *)name; *p; p++)
+ if (!isalpha(*p) && !isdigit(*p) && *p != '-' && *p != '_')
+ *p = '_';
+}
+
int
clk_attach(struct clk *clk)
{
const struct sysctlnode *node;
struct clk_domain *domain = clk->domain;
+ char *name;
+ size_t namelen;
int error;
KASSERT(domain != NULL);
@@ -149,12 +162,17 @@
return 0;
}
+ namelen = strlen(clk->name) + 1;
+ name = kmem_zalloc(namelen, KM_SLEEP);
+ memcpy(name, clk->name, namelen);
+ clk_normalize_name(name);
+
error = create_domain_node(domain);
if (error != 0)
goto sysctl_failed;
error = sysctl_createv(&clk_log, 0, &domain->node, &node,
- CTLFLAG_PRIVATE, CTLTYPE_NODE, clk->name, NULL,
+ CTLFLAG_PRIVATE, CTLTYPE_NODE, name, NULL,
NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
if (error)
goto sysctl_failed;
@@ -182,8 +200,10 @@
sysctl_failed:
if (error)
- aprint_error("%s: failed to create sysctl node for %s: %d\n",
- domain->name, clk->name, error);
+ aprint_error("%s: failed to create sysctl node for %s (%s): %d\n",
+ domain->name, clk->name, name, error);
+
+ kmem_free(name, namelen);
return error;
}
Home |
Main Index |
Thread Index |
Old Index