Re: git: 376330aca184 - main - smbus: add compat32 support for SMB ioctls

From: Jessica Clarke <jrtc27_at_freebsd.org>
Date: Wed, 29 Nov 2023 23:22:31 UTC
On 29 Nov 2023, at 23:16, Stephen J. Kiernan <stevek@FreeBSD.org> wrote:
> 
> The branch main has been updated by stevek:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=376330aca1846d0f7771c16604b41bd7f6f1f14c
> 
> commit 376330aca1846d0f7771c16604b41bd7f6f1f14c
> Author:     Stephen J. Kiernan <stevek@FreeBSD.org>
> AuthorDate: 2023-11-29 19:33:59 +0000
> Commit:     Stephen J. Kiernan <stevek@FreeBSD.org>
> CommitDate: 2023-11-29 23:15:09 +0000
> 
>    smbus: add compat32 support for SMB ioctls
> 
>    Some of the SMB ioctl request structures contain pointers and need to
>    handle requests from 32-bit applications on 64-bit kernels.
> 
>    Obtained from:  Juniper Networks, Inc.
>    Reviewed by:    kib
>    Differential Revision:  https://reviews.freebsd.org/D42837
> ---
> sys/dev/smbus/smb.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 142 insertions(+)
> 
> diff --git a/sys/dev/smbus/smb.c b/sys/dev/smbus/smb.c
> index f47fc753bbdc..ee323c835f10 100644
> --- a/sys/dev/smbus/smb.c
> +++ b/sys/dev/smbus/smb.c
> @@ -2,6 +2,7 @@
>  * SPDX-License-Identifier: BSD-2-Clause
>  *
>  * Copyright (c) 1998, 2001 Nicolas Souchu
> + * Copyright (c) 2023 Juniper Networks, Inc.
>  * All rights reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
> @@ -29,6 +30,7 @@
> #include <sys/param.h>
> #include <sys/kernel.h>
> #include <sys/systm.h>
> +#include <sys/abi_compat.h>
> #include <sys/module.h>
> #include <sys/bus.h>
> #include <sys/conf.h>
> @@ -41,6 +43,44 @@
> 
> #include "smbus_if.h"
> 
> +#ifdef COMPAT_FREEBSD32
> +struct smbcmd32 {
> + u_char cmd;
> + u_char reserved;
> + u_short op;
> + union {
> + char byte;
> + char buf[2];
> + short word;
> + } wdata;
> + union {
> + char byte;
> + char buf[2];
> + short word;
> + } rdata;
> + int slave;
> + uint32_t wbuf;
> + int wcount;
> + uint32_t rbuf;
> + int rcount;
> +};
> +
> +#define SMB_QUICK_WRITE32 _IOW('i', 1, struct smbcmd32)
> +#define SMB_QUICK_READ32 _IOW('i', 2, struct smbcmd32)
> +#define SMB_SENDB32 _IOW('i', 3, struct smbcmd32)
> +#define SMB_RECVB32 _IOWR('i', 4, struct smbcmd32)
> +#define SMB_WRITEB32 _IOW('i', 5, struct smbcmd32)
> +#define SMB_WRITEW32 _IOW('i', 6, struct smbcmd32)
> +#define SMB_READB32 _IOWR('i', 7, struct smbcmd32)
> +#define SMB_READW32 _IOWR('i', 8, struct smbcmd32)
> +#define SMB_PCALL32 _IOWR('i', 9, struct smbcmd32)
> +#define SMB_BWRITE32 _IOW('i', 10, struct smbcmd32)
> +#define SMB_BREAD32 _IOWR('i', 11, struct smbcmd32)
> +#define SMB_OLD_READB32 _IOW('i', 7, struct smbcmd32)
> +#define SMB_OLD_READW32 _IOW('i', 8, struct smbcmd32)
> +#define SMB_OLD_PCALL32 _IOW('i', 9, struct smbcmd32)

You can use _IOC_NEWTYPE to avoid duplicating the encodings.

Jess