From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Jiri Slaby <jirislaby@kernel.org>,
linux-serial@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Jonathan Corbet <corbet@lwn.net>,
Vladimir Zapolskiy <vz@mleia.com>,
Russell King <linux@armlinux.org.uk>,
Richard Genoud <richard.genoud@gmail.com>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Claudiu Beznea <claudiu.beznea@microchip.com>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
NXP Linux Team <linux-imx@nxp.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-stm32@st-md-mailman.stormreply.com,
Lino Sanfilippo <LinoSanfilippo@gmx.de>
Subject: Re: [PATCH v2 4/4] serial: Add kserial_rs485 to avoid wasted space due to .padding
Date: Tue, 30 Aug 2022 10:52:19 +0200 [thread overview]
Message-ID: <Yw3Pw9kwDDKXuqC+@kroah.com> (raw)
In-Reply-To: <20220830072956.3630-5-ilpo.jarvinen@linux.intel.com>
On Tue, Aug 30, 2022 at 10:29:56AM +0300, Ilpo Järvinen wrote:
> -static int serial_rs485_from_user(struct serial_rs485 *rs485,
> +static int serial_rs485_from_user(struct kserial_rs485 *rs485,
> const struct serial_rs485 __user *rs485_user)
> {
> - if (copy_from_user(rs485, rs485_user, sizeof(*rs485)))
> + struct serial_rs485 rs485_uapi;
> +
> + if (copy_from_user(&rs485_uapi, rs485_user, sizeof(*rs485)))
> return -EFAULT;
>
> + *rs485 = *((struct kserial_rs485 *)&rs485_uapi);
Ah, you are mapping this on top of the existing structure, so there was
no padding in the original one, why say that?
> +/*
> + * Compile-time asserts for struct kserial_rs485 and struct serial_rs485 equality
> + * (except padding).
This does not take into account any padding, in fact it's the opposite
as all of this:
> + */
> +static_assert(offsetof(struct kserial_rs485, flags) ==
> + offsetof(struct serial_rs485, flags));
> +static_assert(offsetof(struct kserial_rs485, delay_rts_before_send) ==
> + offsetof(struct serial_rs485, delay_rts_before_send));
> +static_assert(offsetof(struct kserial_rs485, delay_rts_after_send) ==
> + offsetof(struct serial_rs485, delay_rts_after_send));
> +static_assert(offsetof(struct kserial_rs485, addr_recv) ==
> + offsetof(struct serial_rs485, addr_recv));
> +static_assert(offsetof(struct kserial_rs485, addr_dest) ==
> + offsetof(struct serial_rs485, addr_dest));
> +static_assert(sizeof(struct kserial_rs485) <= sizeof(struct serial_rs485));
Is there to ensure that the offsets are exactly the same, no padding
involved anywhere.
So I don't understand the problem you are trying to solve here,
greg k-h
WARNING: multiple messages have this Message-ID (diff)
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
linux-doc@vger.kernel.org,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
linux-kernel@vger.kernel.org, Fabio Estevam <festevam@gmail.com>,
linux-stm32@st-md-mailman.stormreply.com,
Jonathan Corbet <corbet@lwn.net>,
Jiri Slaby <jirislaby@kernel.org>,
Russell King <linux@armlinux.org.uk>,
Lino Sanfilippo <LinoSanfilippo@gmx.de>,
NXP Linux Team <linux-imx@nxp.com>,
linux-serial@vger.kernel.org,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Sascha Hauer <s.hauer@pengutronix.de>,
Vladimir Zapolskiy <vz@mleia.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-arm-kernel@lists.infradead.org,
Richard Genoud <richard.genoud@gmail.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Shawn Guo <shawnguo@kernel.org>,
Claudiu Beznea <claudiu.beznea@microchip.com>
Subject: Re: [PATCH v2 4/4] serial: Add kserial_rs485 to avoid wasted space due to .padding
Date: Tue, 30 Aug 2022 10:52:19 +0200 [thread overview]
Message-ID: <Yw3Pw9kwDDKXuqC+@kroah.com> (raw)
In-Reply-To: <20220830072956.3630-5-ilpo.jarvinen@linux.intel.com>
On Tue, Aug 30, 2022 at 10:29:56AM +0300, Ilpo Järvinen wrote:
> -static int serial_rs485_from_user(struct serial_rs485 *rs485,
> +static int serial_rs485_from_user(struct kserial_rs485 *rs485,
> const struct serial_rs485 __user *rs485_user)
> {
> - if (copy_from_user(rs485, rs485_user, sizeof(*rs485)))
> + struct serial_rs485 rs485_uapi;
> +
> + if (copy_from_user(&rs485_uapi, rs485_user, sizeof(*rs485)))
> return -EFAULT;
>
> + *rs485 = *((struct kserial_rs485 *)&rs485_uapi);
Ah, you are mapping this on top of the existing structure, so there was
no padding in the original one, why say that?
> +/*
> + * Compile-time asserts for struct kserial_rs485 and struct serial_rs485 equality
> + * (except padding).
This does not take into account any padding, in fact it's the opposite
as all of this:
> + */
> +static_assert(offsetof(struct kserial_rs485, flags) ==
> + offsetof(struct serial_rs485, flags));
> +static_assert(offsetof(struct kserial_rs485, delay_rts_before_send) ==
> + offsetof(struct serial_rs485, delay_rts_before_send));
> +static_assert(offsetof(struct kserial_rs485, delay_rts_after_send) ==
> + offsetof(struct serial_rs485, delay_rts_after_send));
> +static_assert(offsetof(struct kserial_rs485, addr_recv) ==
> + offsetof(struct serial_rs485, addr_recv));
> +static_assert(offsetof(struct kserial_rs485, addr_dest) ==
> + offsetof(struct serial_rs485, addr_dest));
> +static_assert(sizeof(struct kserial_rs485) <= sizeof(struct serial_rs485));
Is there to ensure that the offsets are exactly the same, no padding
involved anywhere.
So I don't understand the problem you are trying to solve here,
greg k-h
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-08-30 8:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-30 7:29 [PATCH v2 0/4] serial: Create kserial_rs485 to get rid of padding Ilpo Järvinen
2022-08-30 7:29 ` [PATCH v2 1/4] serial: Rename vars in uart_get_rs485_config() Ilpo Järvinen
2022-08-30 8:54 ` Greg Kroah-Hartman
2022-08-30 9:03 ` Ilpo Järvinen
2022-08-30 7:29 ` [PATCH v2 2/4] serial: add helpers to copy serial_rs485 from/to userspace Ilpo Järvinen
2022-08-30 7:29 ` [PATCH v2 3/4] serial: Convert serial_rs485 to kernel doc Ilpo Järvinen
2022-08-30 7:29 ` [PATCH v2 4/4] serial: Add kserial_rs485 to avoid wasted space due to .padding Ilpo Järvinen
2022-08-30 7:29 ` Ilpo Järvinen
2022-08-30 8:01 ` Jiri Slaby
2022-08-30 8:01 ` Jiri Slaby
2022-08-30 8:44 ` Ilpo Järvinen
2022-08-30 8:44 ` Ilpo Järvinen
2022-08-30 8:49 ` Greg Kroah-Hartman
2022-08-30 8:49 ` Greg Kroah-Hartman
2022-08-30 9:34 ` Ilpo Järvinen
2022-08-30 9:34 ` Ilpo Järvinen
2022-08-30 8:52 ` Greg Kroah-Hartman [this message]
2022-08-30 8:52 ` Greg Kroah-Hartman
2022-08-30 9:26 ` Ilpo Järvinen
2022-08-30 9:26 ` Ilpo Järvinen
2022-08-30 9:33 ` Greg Kroah-Hartman
2022-08-30 9:33 ` Greg Kroah-Hartman
2022-08-30 10:14 ` Ilpo Järvinen
2022-08-30 10:14 ` Ilpo Järvinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yw3Pw9kwDDKXuqC+@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=LinoSanfilippo@gmx.de \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=claudiu.beznea@microchip.com \
--cc=corbet@lwn.net \
--cc=festevam@gmail.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux@armlinux.org.uk \
--cc=mcoquelin.stm32@gmail.com \
--cc=nicolas.ferre@microchip.com \
--cc=richard.genoud@gmail.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=vz@mleia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.