Skip to contentSkip to conversation

mmc-utils: Assert MMC_IOC_MULTI_CMD in compile time

PATCH Applied Avri Altman 2 participants 2 messages Jun 9, 2023 – Jun 12, 2023 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mmc-utils: Assert MMC_IOC_MULTI_CMD in compile time

v1 -> v2: Address Ulf's suggestions

Notify of mult-ioctl violation during preprocessing instead of bailing out in runtime. Would not even allow bogus copies of mmc-utils binaries wondering about out there.

---
 mmc_cmds.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
mmc_cmds.c +4 -12
index df66986..26bdc38 100644
@@ -34,6 +34,10 @@
 #include "mmc_cmds.h"
 #include "3rdparty/hmac_sha/hmac_sha2.h"
 
+#ifndef MMC_IOC_MULTI_CMD
+#error "mmc-utils needs MMC_IOC_MULTI_CMD support (added in kernel v4.4)"
+#endif
+
 #ifndef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
@@ -2112,11 +2116,6 @@ static int do_rpmb_op(int fd,
 					  struct rpmb_frame *frame_out,
 					  unsigned int out_cnt)
 {
-#ifndef MMC_IOC_MULTI_CMD
-	fprintf(stderr, "mmc-utils has been compiled without MMC_IOC_MULTI_CMD"
-		" support, needed by RPMB operation.\n");
-	exit(1);
-#else
 	int err;
 	u_int16_t rpmb_type;
 	struct mmc_ioc_multi_cmd *mioc;
@@ -2196,7 +2195,6 @@ static int do_rpmb_op(int fd,
 out:
 	free(mioc);
 	return err;
-#endif /* !MMC_IOC_MULTI_CMD */
 }
 
 int do_rpmb_write_key(int nargs, char **argv)
@@ -2804,11 +2802,6 @@ out:
 
 int do_ffu(int nargs, char **argv)
 {
-#ifndef MMC_IOC_MULTI_CMD
-	fprintf(stderr, "mmc-utils has been compiled without MMC_IOC_MULTI_CMD"
-			" support, needed by FFU.\n");
-	exit(1);
-#else
 	int dev_fd, img_fd;
 	int sect_done = 0, retry = 3, ret = -EINVAL;
 	unsigned int sect_size;
@@ -3034,7 +3027,6 @@ out:
 	close(img_fd);
 	close(dev_fd);
 	return ret;
-#endif
 }
 
 int do_general_cmd_read(int nargs, char **argv)
Signature · 1 line
2.40.0
Applied
#1 lore raw
Quoted 2 lines · Avri Altman

v1 -> v2: Address Ulf's suggestions

Next time, please put this as patch version information, below the "---".

Quoted 6 lines

Notify of mult-ioctl violation during preprocessing instead of bailing out in runtime. Would not even allow bogus copies of mmc-utils binaries wondering about out there.

Applied to git.kernel.org/pub/scm/utils/mmc/mmc-utils.git master, thanks!

Kind regards
Uffe

Quoted 62 lines
---
 mmc_cmds.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
mmc_cmds.c +4 -13
index df66986..26bdc38 100644
@@ -34,6 +34,10 @@
 #include "mmc_cmds.h"
 #include "3rdparty/hmac_sha/hmac_sha2.h"
 
+#ifndef MMC_IOC_MULTI_CMD
+#error "mmc-utils needs MMC_IOC_MULTI_CMD support (added in kernel v4.4)"
+#endif
+
 #ifndef offsetof
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
@@ -2112,11 +2116,6 @@ static int do_rpmb_op(int fd,
                                          struct rpmb_frame *frame_out,
                                          unsigned int out_cnt)
 {
-#ifndef MMC_IOC_MULTI_CMD
-       fprintf(stderr, "mmc-utils has been compiled without MMC_IOC_MULTI_CMD"
-               " support, needed by RPMB operation.\n");
-       exit(1);
-#else
        int err;
        u_int16_t rpmb_type;
        struct mmc_ioc_multi_cmd *mioc;
@@ -2196,7 +2195,6 @@ static int do_rpmb_op(int fd,
 out:
        free(mioc);
        return err;
-#endif /* !MMC_IOC_MULTI_CMD */
 }
 
 int do_rpmb_write_key(int nargs, char **argv)
@@ -2804,11 +2802,6 @@ out:
 
 int do_ffu(int nargs, char **argv)
 {
-#ifndef MMC_IOC_MULTI_CMD
-       fprintf(stderr, "mmc-utils has been compiled without MMC_IOC_MULTI_CMD"
-                       " support, needed by FFU.\n");
-       exit(1);
-#else
        int dev_fd, img_fd;
        int sect_done = 0, retry = 3, ret = -EINVAL;
        unsigned int sect_size;
@@ -3034,7 +3027,6 @@ out:
        close(img_fd);
        close(dev_fd);
        return ret;
-#endif
 }
 
 int do_general_cmd_read(int nargs, char **argv)
--

2.40.0