Skip to contentSkip to conversation

ALSA: uapi: Replace __packed with __attribute__((packed))

PATCH In review Amadeusz Sławiński 2 participants 4 messages Feb 7, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: uapi: Replace __packed with __attribute__((packed))

Userspace doesn't know what __packed is, change it to __attribute__((packed)), like in the rest of a header.

Fixes 348f48220b97 (ASoC: topology: Move v4 manifest header data structures to uapi)
---
 include/uapi/sound/asoc.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/sound/asoc.h +4 -4
index 6048553c119d..1ae8b06691cb 100644
@@ -586,7 +586,7 @@ struct snd_soc_tplg_manifest_v4 {
 	__le32 pcm_elems;	/* number of PCM elements */
 	__le32 dai_link_elems;	/* number of DAI link elements */
 	struct snd_soc_tplg_private priv;
-} __packed;
+} __attribute((packed));
 
 /* Stream Capabilities v4 */
 struct snd_soc_tplg_stream_caps_v4 {
@@ -604,7 +604,7 @@ struct snd_soc_tplg_stream_caps_v4 {
 	__le32 period_size_max;	/* max period size bytes */
 	__le32 buffer_size_min;	/* min buffer size bytes */
 	__le32 buffer_size_max;	/* max buffer size bytes */
-} __packed;
+} __attribute((packed));
 
 /* PCM v4 */
 struct snd_soc_tplg_pcm_v4 {
@@ -619,7 +619,7 @@ struct snd_soc_tplg_pcm_v4 {
 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */
 	__le32 num_streams;	/* number of streams */
 	struct snd_soc_tplg_stream_caps_v4 caps[2]; /* playback and capture for DAI */
-} __packed;
+} __attribute((packed));
 
 /* Physical link config v4 */
 struct snd_soc_tplg_link_config_v4 {
@@ -627,6 +627,6 @@ struct snd_soc_tplg_link_config_v4 {
 	__le32 id;              /* unique ID - used to match */
 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */
 	__le32 num_streams;     /* number of streams */
-} __packed;
+} __attribute((packed));
 
 #endif
Signature · 6 lines
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#1 lore raw
Quoted 7 lines · Amadeusz Sławiński

Userspace doesn't know what __packed is, change it to __attribute__((packed)), like in the rest of a header.

Fixes 348f48220b97 (ASoC: topology: Move v4 manifest header data structures to uapi)

Is it a general consensus that we have to replace that? Userspace doesn't know of __u16 unless it's defined, either, for example.

thanks,

Takashi

Quoted 46 lines
---
 include/uapi/sound/asoc.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/sound/asoc.h +4 -4
index 6048553c119d..1ae8b06691cb 100644
@@ -586,7 +586,7 @@ struct snd_soc_tplg_manifest_v4 {
 	__le32 pcm_elems;	/* number of PCM elements */
 	__le32 dai_link_elems;	/* number of DAI link elements */
 	struct snd_soc_tplg_private priv;
-} __packed;
+} __attribute((packed));
 
 /* Stream Capabilities v4 */
 struct snd_soc_tplg_stream_caps_v4 {
@@ -604,7 +604,7 @@ struct snd_soc_tplg_stream_caps_v4 {
 	__le32 period_size_max;	/* max period size bytes */
 	__le32 buffer_size_min;	/* min buffer size bytes */
 	__le32 buffer_size_max;	/* max buffer size bytes */
-} __packed;
+} __attribute((packed));
 
 /* PCM v4 */
 struct snd_soc_tplg_pcm_v4 {
@@ -619,7 +619,7 @@ struct snd_soc_tplg_pcm_v4 {
 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */
 	__le32 num_streams;	/* number of streams */
 	struct snd_soc_tplg_stream_caps_v4 caps[2]; /* playback and capture for DAI */
-} __packed;
+} __attribute((packed));
 
 /* Physical link config v4 */
 struct snd_soc_tplg_link_config_v4 {
@@ -627,6 +627,6 @@ struct snd_soc_tplg_link_config_v4 {
 	__le32 id;              /* unique ID - used to match */
 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */
 	__le32 num_streams;     /* number of streams */
-} __packed;
+} __attribute((packed));
 
 #endif
Signature · 1 line
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw
Quoted 11 lines · Takashi Iwai
Quoted 7 lines · Amadeusz Sławiński

Userspace doesn't know what __packed is, change it to __attribute__((packed)), like in the rest of a header.

Fixes 348f48220b97 (ASoC: topology: Move v4 manifest header data structures to uapi)

Is it a general consensus that we have to replace that?

Well, it aligns the packed structs definition with the rest of the file and the program I tried compiling built fine after this adjustment.

As I understand, uapi files are usually installed by scripts/headers_install.pl, which takes care of replacing __packed with __attribute((packed)). However if I do 'make install' in alsa-lib it seems to install this one header containing __packed. In theory alsa-lib also installs /usr/include/alsa/sound/type_compat.h
but to me it seems more like a workaround if I can have working header without additional includes.
Also while there is a few more headers in kernel with __packed, this one is the only one included in alsa-lib and being installed by it:

$ pwd
.../alsa-lib
$ grep -RI __packed *
include/sound/type_compat.h:#ifndef __packed
include/sound/type_compat.h:#define __packed __attribute__((packed))
include/sound/uapi/asoc.h:} __packed;
include/sound/uapi/asoc.h:} __packed;
include/sound/uapi/asoc.h:} __packed;
include/sound/uapi/asoc.h:} __packed;
$ pwd
.../linux
$ grep -RI __packed include/uapi/sound
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/sof/fw.h:} __packed;
include/uapi/sound/sof/fw.h:} __packed;
include/uapi/sound/sof/fw.h:} __packed;
include/uapi/sound/sof/header.h:}  __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
$ grep -RI __packed include/uapi/sound | wc -l
14
$ grep -RI __attribute__\(\(packed include/uapi/sound | wc -l
40

I would say it is better to be consistent.

Quoted 2 lines

Userspace doesn't know of __u16 unless it's defined, either, for example.

The header itself has <linux/types.h> include which seems to be enough to take care of integer type definitions.

Amadeusz

Quoted 47 lines

thanks,

Takashi

Quoted 42 lines
---
  include/uapi/sound/asoc.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/sound/asoc.h +4 -4
index 6048553c119d..1ae8b06691cb 100644
@@ -586,7 +586,7 @@ struct snd_soc_tplg_manifest_v4 {
  	__le32 pcm_elems;	/* number of PCM elements */
  	__le32 dai_link_elems;	/* number of DAI link elements */
  	struct snd_soc_tplg_private priv;
-} __packed;
+} __attribute((packed));
 
  /* Stream Capabilities v4 */
  struct snd_soc_tplg_stream_caps_v4 {
@@ -604,7 +604,7 @@ struct snd_soc_tplg_stream_caps_v4 {
  	__le32 period_size_max;	/* max period size bytes */
  	__le32 buffer_size_min;	/* min buffer size bytes */
  	__le32 buffer_size_max;	/* max buffer size bytes */
-} __packed;
+} __attribute((packed));
 
  /* PCM v4 */
  struct snd_soc_tplg_pcm_v4 {
@@ -619,7 +619,7 @@ struct snd_soc_tplg_pcm_v4 {
  	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */
  	__le32 num_streams;	/* number of streams */
  	struct snd_soc_tplg_stream_caps_v4 caps[2]; /* playback and capture for DAI */
-} __packed;
+} __attribute((packed));
 
  /* Physical link config v4 */
  struct snd_soc_tplg_link_config_v4 {
@@ -627,6 +627,6 @@ struct snd_soc_tplg_link_config_v4 {
  	__le32 id;              /* unique ID - used to match */
  	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */
  	__le32 num_streams;     /* number of streams */
-} __packed;
+} __attribute((packed));
 
Quoted 9 lines
Quoted 4 lines
include/uapi/sound/asoc.h +0 -0
  #endif
Signature · 1 line
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#3 lore raw
Quoted 10 lines · On Fri, 07 Feb 2020 17:02:27 +0100, Amadeusz SX2awiX4ski wrote:
Quoted 8 lines · Takashi Iwai
Quoted 6 lines · Amadeusz Sławiński

Userspace doesn't know what __packed is, change it to __attribute__((packed)), like in the rest of a header.

Fixes 348f48220b97 (ASoC: topology: Move v4 manifest header data structures to uapi)
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Is it a general consensus that we have to replace that?

Well, it aligns the packed structs definition with the rest of the file and the program I tried compiling built fine after this adjustment.

It's a different reason from "userspace doesn't know what __packed is" :)

I'm not against the change, but rather wondering about the rationale behind the changes.

Quoted 4 lines

As I understand, uapi files are usually installed by scripts/headers_install.pl, which takes care of replacing __packed with __attribute((packed)). However if I do 'make install' in alsa-lib it seems to install this one header containing __packed.

This was rather an oversight and we should have converted at copying over the alsa-lib repo. It's not an issue in the kernel header, per se.

thanks,

Takashi

Quoted 39 lines

In theory alsa-lib also installs /usr/include/alsa/sound/type_compat.h but to me it seems more like a workaround if I can have working header without additional includes.
Also while there is a few more headers in kernel with __packed, this one is the only one included in alsa-lib and being installed by it:

$ pwd
.../alsa-lib
$ grep -RI __packed *
include/sound/type_compat.h:#ifndef __packed
include/sound/type_compat.h:#define __packed __attribute__((packed))
include/sound/uapi/asoc.h:} __packed;
include/sound/uapi/asoc.h:} __packed;
include/sound/uapi/asoc.h:} __packed;
include/sound/uapi/asoc.h:} __packed;
$ pwd
.../linux
$ grep -RI __packed include/uapi/sound
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/asoc.h:} __packed;
include/uapi/sound/sof/fw.h:} __packed;
include/uapi/sound/sof/fw.h:} __packed;
include/uapi/sound/sof/fw.h:} __packed;
include/uapi/sound/sof/header.h:}  __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
include/uapi/sound/skl-tplg-interface.h:} __packed;
$ grep -RI __packed include/uapi/sound | wc -l
14
$ grep -RI __attribute__\(\(packed include/uapi/sound | wc -l
40

I would say it is better to be consistent.

Quoted 61 lines
Quoted 2 lines

Userspace doesn't know of __u16 unless it's defined, either, for example.

The header itself has <linux/types.h> include which seems to be enough to take care of integer type definitions.

Amadeusz

Quoted 52 lines

thanks,

Takashi

Quoted 42 lines
---
  include/uapi/sound/asoc.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/uapi/sound/asoc.h +4 -4
index 6048553c119d..1ae8b06691cb 100644
@@ -586,7 +586,7 @@ struct snd_soc_tplg_manifest_v4 {
  	__le32 pcm_elems;	/* number of PCM elements */
  	__le32 dai_link_elems;	/* number of DAI link elements */
  	struct snd_soc_tplg_private priv;
-} __packed;
+} __attribute((packed));
    /* Stream Capabilities v4 */
  struct snd_soc_tplg_stream_caps_v4 {
@@ -604,7 +604,7 @@ struct snd_soc_tplg_stream_caps_v4 {
  	__le32 period_size_max;	/* max period size bytes */
  	__le32 buffer_size_min;	/* min buffer size bytes */
  	__le32 buffer_size_max;	/* max buffer size bytes */
-} __packed;
+} __attribute((packed));
    /* PCM v4 */
  struct snd_soc_tplg_pcm_v4 {
@@ -619,7 +619,7 @@ struct snd_soc_tplg_pcm_v4 {
  	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */
  	__le32 num_streams;	/* number of streams */
  	struct snd_soc_tplg_stream_caps_v4 caps[2]; /* playback and capture for DAI */
-} __packed;
+} __attribute((packed));
    /* Physical link config v4 */
  struct snd_soc_tplg_link_config_v4 {
@@ -627,6 +627,6 @@ struct snd_soc_tplg_link_config_v4 {
  	__le32 id;              /* unique ID - used to match */
  	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */
  	__le32 num_streams;     /* number of streams */
-} __packed;
+} __attribute((packed));
    #endif
Signature · 1 line
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel