Skip to contentSkip to conversation

cmd/misc: Stop using a function pointer

PATCH In review Tom Rini 3 participants 4 messages Jun 22, 2022 – Jun 23, 2022

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 cmd/misc: Stop using a function pointer

Currently, enabling CMD_MISC gives:
cmd/misc.c:67:25: warning: assignment to 'int (*)(struct udevice *, int, void *, int)' from incompatible pointer type 'int (*)(struct udevice *, int, const void *, int)' [-Wincompatible-pointer-types]

Because 'misc_read' takes a void * and 'misc_write' takes a const void *, both of which make sense for their operation. Given there's one place we make use of the function pointer, just call read or write directly for the operation we're called with.

---
 cmd/misc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
cmd/misc.c +2 -4
index bcd8d960ee06..ec32b41ed1e9 100644
@@ -44,7 +44,6 @@ static int do_misc_list(struct cmd_tbl *cmdtp, int flag,
 static int do_misc_op(struct cmd_tbl *cmdtp, int flag,
 		      int argc, char *const argv[], enum misc_op op)
 {
-	int (*misc_op)(struct udevice *, int, void *, int);
 	struct udevice *dev;
 	int offset;
 	void *buf;
@@ -62,11 +61,10 @@ static int do_misc_op(struct cmd_tbl *cmdtp, int flag,
 	size = hextoul(argv[3], NULL);
 
 	if (op == MISC_OP_READ)
-		misc_op = misc_read;
+		ret = misc_read(dev, offset, buf, size);
 	else
-		misc_op = misc_write;
+		ret = misc_write(dev, offset, buf, size);
 
-	ret = misc_op(dev, offset, buf, size);
 	if (ret < 0) {
 		if (ret == -ENOSYS) {
 			printf("The device does not support %s\n",
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Tom Rini

Currently, enabling CMD_MISC gives:
cmd/misc.c:67:25: warning: assignment to 'int (*)(struct udevice *, int, void *, int)' from incompatible pointer type 'int (*)(struct udevice *, int, const void *, int)' [-Wincompatible-pointer-types]

Because 'misc_read' takes a void * and 'misc_write' takes a const void *, both of which make sense for their operation. Given there's one place we make use of the function pointer, just call read or write directly for the operation we're called with.

Quoted 6 lines
---
 cmd/misc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Tom Rini
Quoted 31 lines · Tom Rini

Currently, enabling CMD_MISC gives:
cmd/misc.c:67:25: warning: assignment to 'int (*)(struct udevice *, int, void *, int)' from incompatible pointer type 'int (*)(struct udevice *, int, const void *, int)' [-Wincompatible-pointer-types]

Because 'misc_read' takes a void * and 'misc_write' takes a const void *, both of which make sense for their operation. Given there's one place we make use of the function pointer, just call read or write directly for the operation we're called with.

---
  cmd/misc.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
cmd/misc.c +0 -1
index bcd8d960ee06..ec32b41ed1e9 100644
@@ -44,7 +44,6 @@ static int do_misc_list(struct cmd_tbl *cmdtp, int flag,
  static int do_misc_op(struct cmd_tbl *cmdtp, int flag,
  		      int argc, char *const argv[], enum misc_op op)
  {
-	int (*misc_op)(struct udevice *, int, void *, int);
  	struct udevice *dev;
  	int offset;
  	void *buf;
@@ -62,11 +61,10 @@ static int do_misc_op(struct cmd_tbl *cmdtp, int flag,
  	size = hextoul(argv[3], NULL);
 
  	if (op == MISC_OP_READ)

cmd/misc.c static int do_misc_op(struct cmd_tbl *cmdtp, int flag, · line 70

Quoted 10 lines
cmd/misc.c +2 -3
-		misc_op = misc_read;
+		ret = misc_read(dev, offset, buf, size);
  	else
-		misc_op = misc_write;
+		ret = misc_write(dev, offset, buf, size);
 
-	ret = misc_op(dev, offset, buf, size);
  	if (ret < 0) {
  		if (ret == -ENOSYS) {
  			printf("The device does not support %s\n",
author
#3 lore raw
In reply to Tom Rini
Quoted 11 lines · Tom Rini

Currently, enabling CMD_MISC gives:
cmd/misc.c:67:25: warning: assignment to 'int (*)(struct udevice *, int, void *, int)' from incompatible pointer type 'int (*)(struct udevice *, int, const void *, int)' [-Wincompatible-pointer-types]

Because 'misc_read' takes a void * and 'misc_write' takes a const void *, both of which make sense for their operation. Given there's one place we make use of the function pointer, just call read or write directly for the operation we're called with.

Applied to u-boot/next, thanks!

Signature · 1 line
Tom