diff mbox series

mmc-utils: Assert MMC_IOC_MULTI_CMD in compile time

Message ID 20230524084224.558-1-avri.altman@wdc.com (mailing list archive)
State New, archived
Headers show
Series mmc-utils: Assert MMC_IOC_MULTI_CMD in compile time | expand

Commit Message

Avri Altman May 24, 2023, 8:42 a.m. UTC
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.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
---
 mmc_cmds.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Ulf Hansson June 8, 2023, 9:44 p.m. UTC | #1
On Wed, 24 May 2023 at 10:42, Avri Altman <avri.altman@wdc.com> wrote:
>
> 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.
>
> Signed-off-by: Avri Altman <avri.altman@wdc.com>
> ---
>  mmc_cmds.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index df66986..a4819ab 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -2113,9 +2113,7 @@ static int do_rpmb_op(int fd,
>                                           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);
> +#error "mmc-utils needs MMC_IOC_MULTI_CMD support"
>  #else
>         int err;
>         u_int16_t rpmb_type;
> @@ -2805,9 +2803,7 @@ 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);
> +#error "mmc-utils needs MMC_IOC_MULTI_CMD support"

May I suggest that we have one place in the file to deal with this.
Perhaps put it in the top of the file, immediately after #include"
section.

Moreover, the MMC_IOC_MULTI_CMD support was added in v4.4, so adding
that information as part of the error message would be good too I
think.

>  #else
>         int dev_fd, img_fd;
>         int sect_done = 0, retry = 3, ret = -EINVAL;

Kind regards
Uffe
Avri Altman June 9, 2023, 8:24 a.m. UTC | #2
> >  {
> >  #ifndef MMC_IOC_MULTI_CMD
> > -       fprintf(stderr, "mmc-utils has been compiled without
> MMC_IOC_MULTI_CMD"
> > -                       " support, needed by FFU.\n");
> > -       exit(1);
> > +#error "mmc-utils needs MMC_IOC_MULTI_CMD support"
> 
> May I suggest that we have one place in the file to deal with this.
> Perhaps put it in the top of the file, immediately after #include"
> section.
> 
> Moreover, the MMC_IOC_MULTI_CMD support was added in v4.4, so adding
> that information as part of the error message would be good too I think.
Done.

Thanks,
Avri

> 
> >  #else
> >         int dev_fd, img_fd;
> >         int sect_done = 0, retry = 3, ret = -EINVAL;
> 
> Kind regards
> Uffe
diff mbox series

Patch

diff --git a/mmc_cmds.c b/mmc_cmds.c
index df66986..a4819ab 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -2113,9 +2113,7 @@  static int do_rpmb_op(int fd,
 					  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);
+#error "mmc-utils needs MMC_IOC_MULTI_CMD support"
 #else
 	int err;
 	u_int16_t rpmb_type;
@@ -2805,9 +2803,7 @@  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);
+#error "mmc-utils needs MMC_IOC_MULTI_CMD support"
 #else
 	int dev_fd, img_fd;
 	int sect_done = 0, retry = 3, ret = -EINVAL;