mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: "Bjørn Mork" <bjorn@mork.no>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"USB list" <linux-usb@vger.kernel.org>,
	linux-kernel@vger.kernel.org,
	Linux-Next <linux-next@vger.kernel.org>,
	linux-kbuild <linux-kbuild@vger.kernel.org>,
	Linux/m68k <linux-m68k@vger.kernel.org>
Subject: Re: [PATCH] mod/file2alias: make modalias generation safe for cross compiling
Date: Mon, 25 Jun 2012 22:32:53 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.00.1206252217580.21346@ayla.of.borg> (raw)
In-Reply-To: <m2d34n1sz9.fsf_-_@igel.home>

	Hi Andreas,

On Mon, 25 Jun 2012, Andreas Schwab wrote:
> Use the target compiler to compute the offsets of the fields of the
> device_id structures, so that it won't be broken by different alignments
> between the host and target ABIs.

Thanks, very nice!

> --- a/include/linux/mod_devicetable.h
> +++ b/include/linux/mod_devicetable.h
> @@ -33,8 +33,7 @@ struct ieee1394_device_id {
>  	__u32 model_id;
>  	__u32 specifier_id;
>  	__u32 version;
> -	kernel_ulong_t driver_data
> -		__attribute__((aligned(sizeof(kernel_ulong_t))));
> +	kernel_ulong_t driver_data;

After this, we can also get rid of kernel_ulong_t, but that's a more intruisive
patch all over the place.

> --- /dev/null
> +++ b/scripts/mod/devicetable-offsets.c
> @@ -0,0 +1,171 @@
> +#include <linux/kbuild.h>
> +#include <linux/mod_devicetable.h>
> +
> +#define DEVID(devid) DEFINE(SIZE_##devid, sizeof(struct devid))
> +#define DEVID_FIELD(devid, field) \
> +	DEFINE(OFF_##devid##_##field, offsetof(struct devid, field))
> +
> +int main(void)
> +{
> +	DEVID(usb_device_id);
> +	DEVID_FIELD(usb_device_id, match_flags);
> +	DEVID_FIELD(usb_device_id, idVendor);
> +	DEVID_FIELD(usb_device_id, idProduct);
> +	DEVID_FIELD(usb_device_id, bcdDevice_lo);
> +	DEVID_FIELD(usb_device_id, bcdDevice_hi);
> +	DEVID_FIELD(usb_device_id, bDeviceClass);
> +	DEVID_FIELD(usb_device_id, bDeviceSubClass);
> +	DEVID_FIELD(usb_device_id, bDeviceProtocol);
> +	DEVID_FIELD(usb_device_id, bInterfaceClass);
> +	DEVID_FIELD(usb_device_id, bInterfaceSubClass);
> +	DEVID_FIELD(usb_device_id, bInterfaceProtocol);

These are all duplicates of the structures in <linux/mod_devicetable.h>.
Can't you get rid of the duplication by putting e.g. the following
in <linux/mod_devicetable.h>:

    DEVID_START(usb_device_id);
    DEVID_FIELD(usb_device_id, __u16, match_flags);
    DEVID_FIELD(usb_device_id, __u16, idVendor);
    DEVID_FIELD(usb_device_id, __u16, idProduct);
    DEVID_FIELD(usb_device_id, __u16, bcdDevice_lo);
    DEVID_FIELD(usb_device_id, __u16, bcdDevice_hi);
    DEVID_FIELD(usb_device_id, __u8, bDeviceClass);
    DEVID_FIELD(usb_device_id, __u8, bDeviceSubClass);
    DEVID_FIELD(usb_device_id, __u8, bDeviceProtocol);
    DEVID_FIELD(usb_device_id, __u8, bInterfaceClass);
    DEVID_FIELD(usb_device_id, __u8, bInterfaceSubClass);
    DEVID_FIELD(usb_device_id, __u8, bInterfaceProtocol);
    DEVID_END();

and redefining the DEVID_*() macros depending on
  1. __KERNEL__, to generate the C struct definitions for kernel builds,
  2. first inclusion by devicetable-offsets.c, also to generate C struct
     definitions,
  3. second inclusion by devicetable-offsets.c, to generate the sizes and
     offset definitions for modalias?

> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -116,7 +129,6 @@ static inline void add_wildcard(char *str)
>  		strcat(str + len, "*");
>  }
>  
> -unsigned int cross_build = 0;
>  /**
>   * Check that sizeof(device_id type) are consistent with size of section
>   * in .o file. If in-consistent then userspace and kernel does not agree
> @@ -131,8 +143,6 @@ static void device_id_check(const char *modname, const char *device_id,
>  	int i;
>  
>  	if (size % id_size || size < id_size) {
> -		if (cross_build != 0)
> -			return;
>  		fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
>  		      "of the size of section __mod_%s_device_table=%lu.\n"
>  		      "Fix definition of struct %s_device_id "

Funny, I didn't know there was a check for cross-compiling, supposedly to
ignore the warnings.
And it didn't work, as the problem was noticed originally on the linux-next
build service (which uses cross-compiling), and also showed up for my own
cross-builds.

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

  reply	other threads:[~2012-06-25 20:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-15 17:42 [-next] FATAL: drivers/gpu/drm/udl/udl: sizeof(struct usb_device_id)=24 is not a modulo of the size of section __mod_usb_device_table=44 Geert Uytterhoeven
2012-06-15 20:10 ` Greg Kroah-Hartman
2012-06-15 21:02   ` Geert Uytterhoeven
2012-06-15 23:12     ` Greg Kroah-Hartman
2012-06-16 13:23       ` Bjørn Mork
2012-06-16 15:43         ` Andreas Schwab
2012-06-17 14:00           ` Bjørn Mork
2012-06-17 15:42             ` Andreas Schwab
2012-06-25 12:22             ` [PATCH] mod/file2alias: make modalias generation safe for cross compiling Andreas Schwab
2012-06-25 20:32               ` Geert Uytterhoeven [this message]
2012-06-25 21:43                 ` Andreas Schwab
2012-06-26  5:00               ` Sam Ravnborg
2012-06-26 13:27                 ` [PATCH v2] " Andreas Schwab
2012-06-16 18:33         ` [-next] FATAL: drivers/gpu/drm/udl/udl: sizeof(struct usb_device_id)=24 is not a modulo of the size of section __mod_usb_device_table=44 Philippe De Muyter
2012-06-16 19:11         ` Greg Kroah-Hartman
2012-06-16 19:30           ` Geert Uytterhoeven
2012-06-16 18:51       ` Geert Uytterhoeven
2013-01-20 16:58 [PATCH] mod/file2alias: make modalias generation safe for cross compiling Andreas Schwab
2013-01-24 22:22 ` Michal Marek

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=alpine.DEB.2.00.1206252217580.21346@ayla.of.borg \
    --to=geert@linux-m68k.org \
    --cc=bjorn@mork.no \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=schwab@linux-m68k.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®