mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/3] ACPI: constify first argument of struct acpi_scan_handler::match
@ 2015-09-09 21:59 Rasmus Villemoes
  2015-09-09 21:59 ` [PATCH 2/3] ACPI: constify struct acpi_hardware_id::id Rasmus Villemoes
  2015-09-09 21:59 ` [PATCH 3/3] ACPI / scan: use kstrdup_const in acpi_add_id() Rasmus Villemoes
  0 siblings, 2 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2015-09-09 21:59 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Robert Moore, Lv Zheng
  Cc: Rasmus Villemoes, linux-acpi, linux-kernel, devel

One wouldn't expect a "match" function modify the string it searches
for, and indeed the only instance of the struct
acpi_scan_handler::match callback, acpi_pnp_match, can easily be
changed. While there, update its helper matching_id().

This is also preparation for constifying struct acpi_hardware_id::id.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/acpi/acpi_pnp.c | 4 ++--
 include/acpi/acpi_bus.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/acpi_pnp.c b/drivers/acpi/acpi_pnp.c
index c58940b231d6..48fc3ad13a4b 100644
--- a/drivers/acpi/acpi_pnp.c
+++ b/drivers/acpi/acpi_pnp.c
@@ -316,7 +316,7 @@ static const struct acpi_device_id acpi_pnp_device_ids[] = {
 	{""},
 };
 
-static bool matching_id(char *idstr, char *list_id)
+static bool matching_id(const char *idstr, const char *list_id)
 {
 	int i;
 
@@ -333,7 +333,7 @@ static bool matching_id(char *idstr, char *list_id)
 	return true;
 }
 
-static bool acpi_pnp_match(char *idstr, const struct acpi_device_id **matchid)
+static bool acpi_pnp_match(const char *idstr, const struct acpi_device_id **matchid)
 {
 	const struct acpi_device_id *devid;
 
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 5ba8fb64f664..9a1b46c64fc1 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -129,7 +129,7 @@ static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile(
 struct acpi_scan_handler {
 	const struct acpi_device_id *ids;
 	struct list_head list_node;
-	bool (*match)(char *idstr, const struct acpi_device_id **matchid);
+	bool (*match)(const char *idstr, const struct acpi_device_id **matchid);
 	int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
 	void (*detach)(struct acpi_device *dev);
 	void (*bind)(struct device *phys_dev);
-- 
2.1.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/3] ACPI: constify struct acpi_hardware_id::id
  2015-09-09 21:59 [PATCH 1/3] ACPI: constify first argument of struct acpi_scan_handler::match Rasmus Villemoes
@ 2015-09-09 21:59 ` Rasmus Villemoes
  2015-09-09 21:59 ` [PATCH 3/3] ACPI / scan: use kstrdup_const in acpi_add_id() Rasmus Villemoes
  1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2015-09-09 21:59 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Robert Moore, Lv Zheng
  Cc: Rasmus Villemoes, linux-acpi, linux-kernel, devel

This is preparation for using kstrdup_const to initialize that member.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/acpi/scan.c        | 4 ++--
 drivers/pnp/pnpacpi/core.c | 4 ++--
 include/acpi/acpi_bus.h    | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 01136b879038..a3eaf2080707 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1472,7 +1472,7 @@ bool acpi_device_is_present(struct acpi_device *adev)
 }
 
 static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
-				       char *idstr,
+				       const char *idstr,
 				       const struct acpi_device_id **matchid)
 {
 	const struct acpi_device_id *devid;
@@ -1491,7 +1491,7 @@ static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
 	return false;
 }
 
-static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr,
+static struct acpi_scan_handler *acpi_scan_match_handler(const char *idstr,
 					const struct acpi_device_id **matchid)
 {
 	struct acpi_scan_handler *handler;
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 5153d1d69aee..9113876487ed 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -207,7 +207,7 @@ struct pnp_protocol pnpacpi_protocol = {
 };
 EXPORT_SYMBOL(pnpacpi_protocol);
 
-static char *__init pnpacpi_get_id(struct acpi_device *device)
+static const char *__init pnpacpi_get_id(struct acpi_device *device)
 {
 	struct acpi_hardware_id *id;
 
@@ -222,7 +222,7 @@ static char *__init pnpacpi_get_id(struct acpi_device *device)
 static int __init pnpacpi_add_device(struct acpi_device *device)
 {
 	struct pnp_dev *dev;
-	char *pnpid;
+	const char *pnpid;
 	struct acpi_hardware_id *id;
 	int error;
 
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 9a1b46c64fc1..fec002919b65 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -227,7 +227,7 @@ typedef char acpi_device_class[20];
 
 struct acpi_hardware_id {
 	struct list_head list;
-	char *id;
+	const char *id;
 };
 
 struct acpi_pnp_type {
-- 
2.1.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 3/3] ACPI / scan: use kstrdup_const in acpi_add_id()
  2015-09-09 21:59 [PATCH 1/3] ACPI: constify first argument of struct acpi_scan_handler::match Rasmus Villemoes
  2015-09-09 21:59 ` [PATCH 2/3] ACPI: constify struct acpi_hardware_id::id Rasmus Villemoes
@ 2015-09-09 21:59 ` Rasmus Villemoes
  1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2015-09-09 21:59 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown; +Cc: Rasmus Villemoes, linux-acpi, linux-kernel

Empirically, acpi_add_id is mostly called with string literals, so
using kstrdup_const for initializing struct acpi_hardware_id::id saves
a little run-time memory and a string copy.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/acpi/scan.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index a3eaf2080707..afaac47eefb4 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1184,7 +1184,7 @@ static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id)
 	if (!id)
 		return;
 
-	id->id = kstrdup(dev_id, GFP_KERNEL);
+	id->id = kstrdup_const(dev_id, GFP_KERNEL);
 	if (!id->id) {
 		kfree(id);
 		return;
@@ -1322,7 +1322,7 @@ void acpi_free_pnp_ids(struct acpi_device_pnp *pnp)
 	struct acpi_hardware_id *id, *tmp;
 
 	list_for_each_entry_safe(id, tmp, &pnp->ids, list) {
-		kfree(id->id);
+		kfree_const(id->id);
 		kfree(id);
 	}
 	kfree(pnp->unique_id);
-- 
2.1.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-09 22:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-09 21:59 [PATCH 1/3] ACPI: constify first argument of struct acpi_scan_handler::match Rasmus Villemoes
2015-09-09 21:59 ` [PATCH 2/3] ACPI: constify struct acpi_hardware_id::id Rasmus Villemoes
2015-09-09 21:59 ` [PATCH 3/3] ACPI / scan: use kstrdup_const in acpi_add_id() Rasmus Villemoes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®