mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/5] state: remove param member from struct state_string
@ 2020-01-23 12:20 Christian Eggers
  2020-01-23 12:20 ` [PATCH 2/5] mci: remove param_probe member from struct mci Christian Eggers
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Christian Eggers @ 2020-01-23 12:20 UTC (permalink / raw)
  To: barebox; +Cc: Christian Eggers, ceggers

After adding the parameter, the pointer isn't required anymore.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 common/state/state.h           | 1 -
 common/state/state_variables.c | 7 ++++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/state/state.h b/common/state/state.h
index 912d6d484..40450feff 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -191,7 +191,6 @@ struct state_mac {
  */
 struct state_string {
 	struct state_variable var;
-	struct param_d *param;
 	char *value;
 	const char *value_default;
 	char raw[];
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 6a00c8220..003542307 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -413,6 +413,7 @@ static struct state_variable *state_string_create(struct state *state,
 {
 	struct state_string *string;
 	uint32_t start_size[2];
+	struct param_d *param;
 	int ret;
 
 	ret = of_property_read_u32_array(node, "reg", start_size,
@@ -432,11 +433,11 @@ static struct state_variable *state_string_create(struct state *state,
 	string->var.raw = &string->raw;
 	string->var.state = state;
 
-	string->param = dev_add_param_string(&state->dev, name,
+	param = dev_add_param_string(&state->dev, name,
 					     state_string_set, state_string_get,
 					     &string->value, &string->var);
-	if (IS_ERR(string->param)) {
-		ret = PTR_ERR(string->param);
+	if (IS_ERR(param)) {
+		ret = PTR_ERR(param);
 		goto out;
 	}
 
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/5] mci: remove param_probe member from struct mci
  2020-01-23 12:20 [PATCH 1/5] state: remove param member from struct state_string Christian Eggers
@ 2020-01-23 12:20 ` Christian Eggers
  2020-01-23 12:20 ` [PATCH 3/5] state: remove param member from state_uint32, state_enum32, state_mac Christian Eggers
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Eggers @ 2020-01-23 12:20 UTC (permalink / raw)
  To: barebox; +Cc: Christian Eggers, ceggers

After adding the parameter, the pointer isn't required anymore.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 drivers/mci/mci-core.c | 7 ++++---
 include/mci.h          | 1 -
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 67257bcd1..7f2d3d46d 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1798,6 +1798,7 @@ static int mci_detect(struct device_d *dev)
 int mci_register(struct mci_host *host)
 {
 	struct mci *mci;
+	struct param_d *param_probe;
 	int ret;
 
 	mci = xzalloc(sizeof(*mci));
@@ -1829,11 +1830,11 @@ int mci_register(struct mci_host *host)
 
 	dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(&mci->dev));
 
-	mci->param_probe = dev_add_param_bool(&mci->dev, "probe",
+	param_probe = dev_add_param_bool(&mci->dev, "probe",
 			mci_set_probe, NULL, &mci->probe, mci);
 
-	if (IS_ERR(mci->param_probe) && PTR_ERR(mci->param_probe) != -ENOSYS) {
-		ret = PTR_ERR(mci->param_probe);
+	if (IS_ERR(param_probe) && PTR_ERR(param_probe) != -ENOSYS) {
+		ret = PTR_ERR(param_probe);
 		dev_dbg(&mci->dev, "Failed to add 'probe' parameter to the MCI device\n");
 		goto err_unregister;
 	}
diff --git a/include/mci.h b/include/mci.h
index a45d74476..96150739f 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -468,7 +468,6 @@ struct mci {
 	int dsr_imp;		/**< DSR implementation state from CSD */
 	char *ext_csd;
 	int probe;
-	struct param_d *param_probe;
 	struct param_d *param_boot;
 	int bootpart;
 
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/5] state: remove param member from state_uint32, state_enum32, state_mac
  2020-01-23 12:20 [PATCH 1/5] state: remove param member from struct state_string Christian Eggers
  2020-01-23 12:20 ` [PATCH 2/5] mci: remove param_probe member from struct mci Christian Eggers
@ 2020-01-23 12:20 ` Christian Eggers
  2020-01-23 12:20 ` [PATCH 4/5] globalvar: Allow NULL pointers to be returned by dev_add_param() Christian Eggers
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Eggers @ 2020-01-23 12:20 UTC (permalink / raw)
  To: barebox; +Cc: Christian Eggers, ceggers

After adding the parameter, the pointer isn't required anymore.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 common/state/state.h           |  3 ---
 common/state/state_variables.c | 16 ++++++++--------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/common/state/state.h b/common/state/state.h
index 40450feff..1881d92ea 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -159,7 +159,6 @@ struct state_variable {
  */
 struct state_uint32 {
 	struct state_variable var;
-	struct param_d *param;
 	uint32_t value;
 	uint32_t value_default;
 };
@@ -169,7 +168,6 @@ struct state_uint32 {
  */
 struct state_enum32 {
 	struct state_variable var;
-	struct param_d *param;
 	uint32_t value;
 	uint32_t value_default;
 	const char **names;
@@ -181,7 +179,6 @@ struct state_enum32 {
  */
 struct state_mac {
 	struct state_variable var;
-	struct param_d *param;
 	uint8_t value[6];
 	uint8_t value_default[6];
 };
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 003542307..66c66f38b 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -116,7 +116,6 @@ static struct state_variable *state_uint8_create(struct state *state,
 		return ERR_CAST(param);
 	}
 
-	su32->param = param;
 	su32->var.type = vtype;
 	su32->var.size = sizeof(uint8_t);
 #ifdef __LITTLE_ENDIAN
@@ -146,7 +145,6 @@ static struct state_variable *state_uint32_create(struct state *state,
 		return ERR_CAST(param);
 	}
 
-	su32->param = param;
 	su32->var.type = vtype;
 	su32->var.size = sizeof(uint32_t);
 	su32->var.raw = &su32->value;
@@ -226,6 +224,7 @@ static struct state_variable *state_enum32_create(struct state *state,
 						  const struct variable_type *vtype)
 {
 	struct state_enum32 *enum32;
+	struct param_d *param;
 	int ret, i, num_names;
 
 	enum32 = xzalloc(sizeof(*enum32));
@@ -253,11 +252,11 @@ static struct state_variable *state_enum32_create(struct state *state,
 		enum32->names[i] = xstrdup(name);
 	}
 
-	enum32->param = dev_add_param_enum(&state->dev, name, state_set_dirty,
+	param = dev_add_param_enum(&state->dev, name, state_set_dirty,
 					   NULL, &enum32->value, enum32->names,
 					   num_names, &enum32->var);
-	if (IS_ERR(enum32->param)) {
-		ret = PTR_ERR(enum32->param);
+	if (IS_ERR(param)) {
+		ret = PTR_ERR(param);
 		goto out;
 	}
 
@@ -310,6 +309,7 @@ static struct state_variable *state_mac_create(struct state *state,
 					       const struct variable_type *vtype)
 {
 	struct state_mac *mac;
+	struct param_d *param;
 	int ret;
 
 	mac = xzalloc(sizeof(*mac));
@@ -319,10 +319,10 @@ static struct state_variable *state_mac_create(struct state *state,
 	mac->var.raw = mac->value;
 	mac->var.state = state;
 
-	mac->param = dev_add_param_mac(&state->dev, name, state_set_dirty,
+	param = dev_add_param_mac(&state->dev, name, state_set_dirty,
 				       NULL, mac->value, &mac->var);
-	if (IS_ERR(mac->param)) {
-		ret = PTR_ERR(mac->param);
+	if (IS_ERR(param)) {
+		ret = PTR_ERR(param);
 		goto out;
 	}
 
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 4/5] globalvar: Allow NULL pointers to be returned by dev_add_param()
  2020-01-23 12:20 [PATCH 1/5] state: remove param member from struct state_string Christian Eggers
  2020-01-23 12:20 ` [PATCH 2/5] mci: remove param_probe member from struct mci Christian Eggers
  2020-01-23 12:20 ` [PATCH 3/5] state: remove param member from state_uint32, state_enum32, state_mac Christian Eggers
@ 2020-01-23 12:20 ` Christian Eggers
  2020-01-23 12:20 ` [PATCH 5/5] parameter: Return NULL instead of ENOSYS if CONFIG_PARAMETER is disabled Christian Eggers
  2020-01-27  9:58 ` [PATCH 1/5] state: remove param member from struct state_string Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Eggers @ 2020-01-23 12:20 UTC (permalink / raw)
  To: barebox; +Cc: Christian Eggers, ceggers

The following commit will change the return value of dev_add_param()
from -ENOSYS to NULL if CONFIG_PARAMETER is disabled. After that,
building without CONFIG_PARAMETER will return a NULL pointer to
__nvvar_add() instead of an error.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 common/globalvar.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index cec0a9cc4..8dcbc04bd 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -166,21 +166,24 @@ static int nvvar_device_dispatch(const char *name, struct device_d **dev,
 	return 1;
 }
 
-static int nv_set(struct device_d *dev, struct param_d *p, const char *val)
+static int nv_set(struct device_d *dev, struct param_d *p, const char *name, const char *val)
 {
 	int ret;
 
 	if (!val) {
-		free(p->value);
+		if (p)
+			free(p->value);
 		return 0;
 	}
 
-	ret = dev_set_param(&global_device, p->name, val);
+	ret = dev_set_param(&global_device, name, val);
 	if (ret)
 		return ret;
 
-	free(p->value);
-	p->value = xstrdup(val);
+	if (p) {
+		free(p->value);
+		p->value = xstrdup(val);
+	}
 
 	return 0;
 }
@@ -194,7 +197,7 @@ static int nv_param_set(struct device_d *dev, struct param_d *p, const char *val
 {
 	int ret;
 
-	ret = nv_set(dev, p, val);
+	ret = nv_set(dev, p, p->name, val);
 	if (ret)
 		return ret;
 
@@ -225,7 +228,7 @@ static int __nvvar_add(const char *name, const char *value)
 		return ret;
 
 	if (value)
-		return nv_set(&nv_device, p, value);
+		return nv_set(&nv_device, p, name, value);
 
 	ret = nvvar_device_dispatch(name, &dev, &pname);
 	if (ret > 0)
@@ -233,7 +236,7 @@ static int __nvvar_add(const char *name, const char *value)
 	else
 		value = dev_get_param(&global_device, name);
 
-	if (value) {
+	if (value && p) {
 		free(p->value);
 		p->value = xstrdup(value);
 	}
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 5/5] parameter: Return NULL instead of ENOSYS if CONFIG_PARAMETER is disabled
  2020-01-23 12:20 [PATCH 1/5] state: remove param member from struct state_string Christian Eggers
                   ` (2 preceding siblings ...)
  2020-01-23 12:20 ` [PATCH 4/5] globalvar: Allow NULL pointers to be returned by dev_add_param() Christian Eggers
@ 2020-01-23 12:20 ` Christian Eggers
  2020-01-27  9:58 ` [PATCH 1/5] state: remove param member from struct state_string Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Eggers @ 2020-01-23 12:20 UTC (permalink / raw)
  To: barebox; +Cc: Christian Eggers, ceggers

This reverts 03b59bdb64 ("paramter: The dev_add_param_*() return
ERR_PTR(), change no-ops to return ERR_PTR(-ENOSYS) instead of NULL").

Most callers of dev_add_param_*() don't care about whether
CONFIG_PARAMETER is enabled or not. The remaining ones have already been
prepared for getting a NULL pointer. As a result, these callers will not
fail itself, only because CONFIG_PARAMETER (which is always optional) is
disabled.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 include/param.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/param.h b/include/param.h
index f1166eb28..c79b908b1 100644
--- a/include/param.h
+++ b/include/param.h
@@ -118,7 +118,7 @@ static inline struct param_d *dev_add_param(struct device_d *dev, const char *na
 		const char *(*get)(struct device_d *, struct param_d *p),
 		unsigned long flags)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_string(struct device_d *dev, const char *name,
@@ -126,7 +126,7 @@ static inline struct param_d *dev_add_param_string(struct device_d *dev, const c
 		int (*get)(struct param_d *p, void *priv),
 		char **value, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *__dev_add_param_int(struct device_d *dev, const char *name,
@@ -134,7 +134,7 @@ static inline struct param_d *__dev_add_param_int(struct device_d *dev, const ch
 		int (*get)(struct param_d *p, void *priv),
 		void *value, enum param_type type, const char *format, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_enum(struct device_d *dev, const char *name,
@@ -143,7 +143,7 @@ static inline struct param_d *dev_add_param_enum(struct device_d *dev, const cha
 		int *value, const char * const *names, int max, void *priv)
 
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_bitmask(struct device_d *dev, const char *name,
@@ -151,7 +151,7 @@ static inline struct param_d *dev_add_param_bitmask(struct device_d *dev, const
                 int (*get)(struct param_d *p, void *priv),
                 unsigned long *value, const char * const *names, int max, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_tristate(struct device_d *dev, const char *name,
@@ -159,13 +159,13 @@ static inline struct param_d *dev_add_param_tristate(struct device_d *dev, const
 		int (*get)(struct param_d *p, void *priv),
 		int *value, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_tristate_ro(struct device_d *dev, const char *name,
 		int *value)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
@@ -173,7 +173,7 @@ static inline struct param_d *dev_add_param_ip(struct device_d *dev, const char
 		int (*get)(struct param_d *p, void *priv),
 		IPaddr_t *ip, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_mac(struct device_d *dev, const char *name,
@@ -181,13 +181,13 @@ static inline struct param_d *dev_add_param_mac(struct device_d *dev, const char
 		int (*get)(struct param_d *p, void *priv),
 		u8 *mac, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline struct param_d *dev_add_param_fixed(struct device_d *dev, const char *name,
 						  const char *value)
 {
-	return ERR_PTR(-ENOSYS);
+	return NULL;
 }
 
 static inline void dev_remove_param(struct param_d *p) {}
-- 
Christian Eggers
Embedded software developer

Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRA 57918
Persoenlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: Muenchen - Registergericht: Amtsgericht Muenchen - Handelsregisternummer: HRB 54477
Geschaeftsfuehrer: Dr. Michael Neuhaeuser; Stephan Schenk; Walter Trauninger; Markus Zeiler


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 1/5] state: remove param member from struct state_string
  2020-01-23 12:20 [PATCH 1/5] state: remove param member from struct state_string Christian Eggers
                   ` (3 preceding siblings ...)
  2020-01-23 12:20 ` [PATCH 5/5] parameter: Return NULL instead of ENOSYS if CONFIG_PARAMETER is disabled Christian Eggers
@ 2020-01-27  9:58 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2020-01-27  9:58 UTC (permalink / raw)
  To: Christian Eggers; +Cc: barebox, ceggers

On Thu, Jan 23, 2020 at 01:20:41PM +0100, Christian Eggers wrote:
> After adding the parameter, the pointer isn't required anymore.
> 
> Signed-off-by: Christian Eggers <ceggers@arri.de>
> ---
>  common/state/state.h           | 1 -
>  common/state/state_variables.c | 7 ++++---
>  2 files changed, 4 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-01-27  9:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-23 12:20 [PATCH 1/5] state: remove param member from struct state_string Christian Eggers
2020-01-23 12:20 ` [PATCH 2/5] mci: remove param_probe member from struct mci Christian Eggers
2020-01-23 12:20 ` [PATCH 3/5] state: remove param member from state_uint32, state_enum32, state_mac Christian Eggers
2020-01-23 12:20 ` [PATCH 4/5] globalvar: Allow NULL pointers to be returned by dev_add_param() Christian Eggers
2020-01-23 12:20 ` [PATCH 5/5] parameter: Return NULL instead of ENOSYS if CONFIG_PARAMETER is disabled Christian Eggers
2020-01-27  9:58 ` [PATCH 1/5] state: remove param member from struct state_string Sascha Hauer

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