Skip to content

Commit 2da38e0

Browse files
Vinod Koultiwai
authored andcommitted
ALSA: compress: fix the struct alignment to 4 bytes
In 64bit systems the compiler can default align to 8bytes causing mis-match with 32bit usermode. Avoid this is future by ensuring all the structures shared with usermode are packed and aligned to 4 bytes irrespective of arch used [coding style fixes by tiwai] Signed-off-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 8d42fda commit 2da38e0

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎include/uapi/sound/compress_offload.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
struct snd_compressed_buffer {
4040
__u32 fragment_size;
4141
__u32 fragments;
42-
};
42+
} __attribute__((packed, aligned(4)));
4343

4444
/**
4545
* struct snd_compr_params: compressed stream params
@@ -51,7 +51,7 @@ struct snd_compr_params {
5151
struct snd_compressed_buffer buffer;
5252
struct snd_codec codec;
5353
__u8 no_wake_mode;
54-
};
54+
} __attribute__((packed, aligned(4)));
5555

5656
/**
5757
* struct snd_compr_tstamp: timestamp descriptor
@@ -70,7 +70,7 @@ struct snd_compr_tstamp {
7070
__u32 pcm_frames;
7171
__u32 pcm_io_frames;
7272
__u32 sampling_rate;
73-
};
73+
} __attribute__((packed, aligned(4)));
7474

7575
/**
7676
* struct snd_compr_avail: avail descriptor
@@ -80,7 +80,7 @@ struct snd_compr_tstamp {
8080
struct snd_compr_avail {
8181
__u64 avail;
8282
struct snd_compr_tstamp tstamp;
83-
} __attribute__((packed));
83+
} __attribute__((packed, aligned(4)));
8484

8585
enum snd_compr_direction {
8686
SND_COMPRESS_PLAYBACK = 0,
@@ -107,7 +107,7 @@ struct snd_compr_caps {
107107
__u32 max_fragments;
108108
__u32 codecs[MAX_NUM_CODECS];
109109
__u32 reserved[11];
110-
};
110+
} __attribute__((packed, aligned(4)));
111111

112112
/**
113113
* struct snd_compr_codec_caps: query capability of codec
@@ -119,7 +119,7 @@ struct snd_compr_codec_caps {
119119
__u32 codec;
120120
__u32 num_descriptors;
121121
struct snd_codec_desc descriptor[MAX_NUM_CODEC_DESCRIPTORS];
122-
};
122+
} __attribute__((packed, aligned(4)));
123123

124124
/**
125125
* @SNDRV_COMPRESS_ENCODER_PADDING: no of samples appended by the encoder at the
@@ -140,7 +140,7 @@ enum {
140140
struct snd_compr_metadata {
141141
__u32 key;
142142
__u32 value[8];
143-
};
143+
} __attribute__((packed, aligned(4)));
144144

145145
/**
146146
* compress path ioctl definitions

‎include/uapi/sound/compress_params.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ struct snd_enc_vorbis {
268268
__u32 max_bit_rate;
269269
__u32 min_bit_rate;
270270
__u32 downmix;
271-
};
271+
} __attribute__((packed, aligned(4)));
272272

273273

274274
/**
@@ -284,7 +284,7 @@ struct snd_enc_real {
284284
__u32 quant_bits;
285285
__u32 start_region;
286286
__u32 num_regions;
287-
};
287+
} __attribute__((packed, aligned(4)));
288288

289289
/**
290290
* struct snd_enc_flac
@@ -308,20 +308,20 @@ struct snd_enc_real {
308308
struct snd_enc_flac {
309309
__u32 num;
310310
__u32 gain;
311-
};
311+
} __attribute__((packed, aligned(4)));
312312

313313
struct snd_enc_generic {
314314
__u32 bw; /* encoder bandwidth */
315315
__s32 reserved[15];
316-
};
316+
} __attribute__((packed, aligned(4)));
317317

318318
union snd_codec_options {
319319
struct snd_enc_wma wma;
320320
struct snd_enc_vorbis vorbis;
321321
struct snd_enc_real real;
322322
struct snd_enc_flac flac;
323323
struct snd_enc_generic generic;
324-
};
324+
} __attribute__((packed, aligned(4)));
325325

326326
/** struct snd_codec_desc - description of codec capabilities
327327
* @max_ch: Maximum number of audio channels
@@ -358,7 +358,7 @@ struct snd_codec_desc {
358358
__u32 formats;
359359
__u32 min_buffer;
360360
__u32 reserved[15];
361-
};
361+
} __attribute__((packed, aligned(4)));
362362

363363
/** struct snd_codec
364364
* @id: Identifies the supported audio encoder/decoder.
@@ -399,6 +399,6 @@ struct snd_codec {
399399
__u32 align;
400400
union snd_codec_options options;
401401
__u32 reserved[3];
402-
};
402+
} __attribute__((packed, aligned(4)));
403403

404404
#endif

0 commit comments

Comments
 (0)