Skip to content

Commit fcae40c

Browse files
wangbaolin719arndb
authored andcommitted
ALSA: Replace timespec with timespec64
Since timespec is not year 2038 safe on 32bit system, and we need to convert all timespec variables to timespec64 type for sound subsystem. This patch is used to do preparation for following patches, that will convert all structures defined in uapi/sound/asound.h to use 64-bit time_t. Signed-off-by: Baolin Wang <baolin.wang@linaro.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent e42617b commit fcae40c

9 files changed

Lines changed: 65 additions & 53 deletions

File tree

‎include/sound/pcm.h‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct snd_pcm_ops {
6262
int (*sync_stop)(struct snd_pcm_substream *substream);
6363
snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
6464
int (*get_time_info)(struct snd_pcm_substream *substream,
65-
struct timespec *system_ts, struct timespec *audio_ts,
65+
struct timespec64 *system_ts, struct timespec64 *audio_ts,
6666
struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
6767
struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
6868
int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
@@ -343,7 +343,7 @@ static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy
343343
struct snd_pcm_runtime {
344344
/* -- Status -- */
345345
struct snd_pcm_substream *trigger_master;
346-
struct timespec trigger_tstamp; /* trigger timestamp */
346+
struct timespec64 trigger_tstamp; /* trigger timestamp */
347347
bool trigger_tstamp_latched; /* trigger timestamp latched in low-level driver/hardware */
348348
int overrange;
349349
snd_pcm_uframes_t avail_max;
@@ -421,7 +421,7 @@ struct snd_pcm_runtime {
421421
/* -- audio timestamp config -- */
422422
struct snd_pcm_audio_tstamp_config audio_tstamp_config;
423423
struct snd_pcm_audio_tstamp_report audio_tstamp_report;
424-
struct timespec driver_tstamp;
424+
struct timespec64 driver_tstamp;
425425

426426
#if IS_ENABLED(CONFIG_SND_PCM_OSS)
427427
/* -- OSS things -- */
@@ -1155,22 +1155,22 @@ static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substrea
11551155
}
11561156

11571157
/**
1158-
* snd_pcm_gettime - Fill the timespec depending on the timestamp mode
1158+
* snd_pcm_gettime - Fill the timespec64 depending on the timestamp mode
11591159
* @runtime: PCM runtime instance
1160-
* @tv: timespec to fill
1160+
* @tv: timespec64 to fill
11611161
*/
11621162
static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
1163-
struct timespec *tv)
1163+
struct timespec64 *tv)
11641164
{
11651165
switch (runtime->tstamp_type) {
11661166
case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
1167-
ktime_get_ts(tv);
1167+
ktime_get_ts64(tv);
11681168
break;
11691169
case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
1170-
getrawmonotonic(tv);
1170+
ktime_get_raw_ts64(tv);
11711171
break;
11721172
default:
1173-
getnstimeofday(tv);
1173+
ktime_get_real_ts64(tv);
11741174
break;
11751175
}
11761176
}

‎include/sound/soc-component.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ struct snd_soc_component_driver {
9393
snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
9494
struct snd_pcm_substream *substream);
9595
int (*get_time_info)(struct snd_soc_component *component,
96-
struct snd_pcm_substream *substream, struct timespec *system_ts,
97-
struct timespec *audio_ts,
96+
struct snd_pcm_substream *substream, struct timespec64 *system_ts,
97+
struct timespec64 *audio_ts,
9898
struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
9999
struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
100100
int (*copy_user)(struct snd_soc_component *component,

‎include/sound/timer.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct snd_timer_instance {
8989
unsigned long ticks, unsigned long resolution);
9090
void (*ccallback) (struct snd_timer_instance * timeri,
9191
int event,
92-
struct timespec * tstamp,
92+
struct timespec64 * tstamp,
9393
unsigned long resolution);
9494
void (*disconnect)(struct snd_timer_instance *timeri);
9595
void *callback_data;
@@ -113,7 +113,7 @@ struct snd_timer_instance {
113113
*/
114114

115115
int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
116-
void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp);
116+
void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp);
117117
int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
118118
int snd_timer_global_free(struct snd_timer *timer);
119119
int snd_timer_global_register(struct snd_timer *timer);

‎sound/core/pcm_lib.c‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ void __snd_pcm_xrun(struct snd_pcm_substream *substream)
144144
struct snd_pcm_runtime *runtime = substream->runtime;
145145

146146
trace_xrun(substream);
147-
if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE)
148-
snd_pcm_gettime(runtime, (struct timespec *)&runtime->status->tstamp);
147+
if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
148+
struct timespec64 tstamp;
149+
150+
snd_pcm_gettime(runtime, &tstamp);
151+
runtime->status->tstamp = timespec64_to_timespec(tstamp);
152+
}
149153
snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
150154
if (xrun_debug(substream, XRUN_DEBUG_BASIC)) {
151155
char name[16];
@@ -200,12 +204,12 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream,
200204
}
201205

202206
static void update_audio_tstamp(struct snd_pcm_substream *substream,
203-
struct timespec *curr_tstamp,
204-
struct timespec *audio_tstamp)
207+
struct timespec64 *curr_tstamp,
208+
struct timespec64 *audio_tstamp)
205209
{
206210
struct snd_pcm_runtime *runtime = substream->runtime;
207211
u64 audio_frames, audio_nsecs;
208-
struct timespec driver_tstamp;
212+
struct timespec64 driver_tstamp;
209213

210214
if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE)
211215
return;
@@ -229,18 +233,22 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream,
229233
}
230234
audio_nsecs = div_u64(audio_frames * 1000000000LL,
231235
runtime->rate);
232-
*audio_tstamp = ns_to_timespec(audio_nsecs);
236+
*audio_tstamp = ns_to_timespec64(audio_nsecs);
233237
}
234-
if (!timespec_equal(&runtime->status->audio_tstamp, audio_tstamp)) {
235-
runtime->status->audio_tstamp = *audio_tstamp;
236-
runtime->status->tstamp = *curr_tstamp;
238+
239+
if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec ||
240+
runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) {
241+
runtime->status->audio_tstamp =
242+
timespec64_to_timespec(*audio_tstamp);
243+
runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp);
237244
}
238245

246+
239247
/*
240248
* re-take a driver timestamp to let apps detect if the reference tstamp
241249
* read by low-level hardware was provided with a delay
242250
*/
243-
snd_pcm_gettime(substream->runtime, (struct timespec *)&driver_tstamp);
251+
snd_pcm_gettime(substream->runtime, &driver_tstamp);
244252
runtime->driver_tstamp = driver_tstamp;
245253
}
246254

@@ -253,8 +261,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
253261
snd_pcm_sframes_t hdelta, delta;
254262
unsigned long jdelta;
255263
unsigned long curr_jiffies;
256-
struct timespec curr_tstamp;
257-
struct timespec audio_tstamp;
264+
struct timespec64 curr_tstamp;
265+
struct timespec64 audio_tstamp;
258266
int crossed_boundary = 0;
259267

260268
old_hw_ptr = runtime->status->hw_ptr;
@@ -277,9 +285,9 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
277285

278286
/* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */
279287
if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)
280-
snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
288+
snd_pcm_gettime(runtime, &curr_tstamp);
281289
} else
282-
snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
290+
snd_pcm_gettime(runtime, &curr_tstamp);
283291
}
284292

285293
if (pos == SNDRV_PCM_POS_XRUN) {

‎sound/core/pcm_native.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
918918
status->suspended_state = runtime->status->suspended_state;
919919
if (status->state == SNDRV_PCM_STATE_OPEN)
920920
goto _end;
921-
status->trigger_tstamp = runtime->trigger_tstamp;
921+
status->trigger_tstamp = timespec64_to_timespec(runtime->trigger_tstamp);
922922
if (snd_pcm_running(substream)) {
923923
snd_pcm_update_hw_ptr(substream);
924924
if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
925925
status->tstamp = runtime->status->tstamp;
926-
status->driver_tstamp = runtime->driver_tstamp;
926+
status->driver_tstamp = timespec64_to_timespec(runtime->driver_tstamp);
927927
status->audio_tstamp =
928928
runtime->status->audio_tstamp;
929929
if (runtime->audio_tstamp_report.valid == 1)
@@ -936,8 +936,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
936936
}
937937
} else {
938938
/* get tstamp only in fallback mode and only if enabled */
939-
if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE)
940-
snd_pcm_gettime(runtime, &status->tstamp);
939+
if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
940+
struct timespec64 tstamp;
941+
942+
snd_pcm_gettime(runtime, &tstamp);
943+
status->tstamp = timespec64_to_timespec(tstamp);
944+
}
941945
}
942946
_tstamp_end:
943947
status->appl_ptr = runtime->control->appl_ptr;

‎sound/core/timer.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct snd_timer_user {
5959
spinlock_t qlock;
6060
unsigned long last_resolution;
6161
unsigned int filter;
62-
struct timespec tstamp; /* trigger tstamp */
62+
struct timespec64 tstamp; /* trigger tstamp */
6363
wait_queue_head_t qchange_sleep;
6464
struct fasync_struct *fasync;
6565
struct mutex ioctl_lock;
@@ -453,12 +453,12 @@ static void snd_timer_notify1(struct snd_timer_instance *ti, int event)
453453
struct snd_timer *timer = ti->timer;
454454
unsigned long resolution = 0;
455455
struct snd_timer_instance *ts;
456-
struct timespec tstamp;
456+
struct timespec64 tstamp;
457457

458458
if (timer_tstamp_monotonic)
459-
ktime_get_ts(&tstamp);
459+
ktime_get_ts64(&tstamp);
460460
else
461-
getnstimeofday(&tstamp);
461+
ktime_get_real_ts64(&tstamp);
462462
if (snd_BUG_ON(event < SNDRV_TIMER_EVENT_START ||
463463
event > SNDRV_TIMER_EVENT_PAUSE))
464464
return;
@@ -1025,7 +1025,7 @@ static int snd_timer_dev_disconnect(struct snd_device *device)
10251025
return 0;
10261026
}
10271027

1028-
void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp)
1028+
void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp)
10291029
{
10301030
unsigned long flags;
10311031
unsigned long resolution = 0;
@@ -1318,7 +1318,7 @@ static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu,
13181318

13191319
static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
13201320
int event,
1321-
struct timespec *tstamp,
1321+
struct timespec64 *tstamp,
13221322
unsigned long resolution)
13231323
{
13241324
struct snd_timer_user *tu = timeri->callback_data;
@@ -1332,7 +1332,7 @@ static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
13321332
return;
13331333
memset(&r1, 0, sizeof(r1));
13341334
r1.event = event;
1335-
r1.tstamp = *tstamp;
1335+
r1.tstamp = timespec64_to_timespec(*tstamp);
13361336
r1.val = resolution;
13371337
spin_lock_irqsave(&tu->qlock, flags);
13381338
snd_timer_user_append_to_tqueue(tu, &r1);
@@ -1355,7 +1355,7 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
13551355
{
13561356
struct snd_timer_user *tu = timeri->callback_data;
13571357
struct snd_timer_tread *r, r1;
1358-
struct timespec tstamp;
1358+
struct timespec64 tstamp;
13591359
int prev, append = 0;
13601360

13611361
memset(&r1, 0, sizeof(r1));
@@ -1368,14 +1368,14 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
13681368
}
13691369
if (tu->last_resolution != resolution || ticks > 0) {
13701370
if (timer_tstamp_monotonic)
1371-
ktime_get_ts(&tstamp);
1371+
ktime_get_ts64(&tstamp);
13721372
else
1373-
getnstimeofday(&tstamp);
1373+
ktime_get_real_ts64(&tstamp);
13741374
}
13751375
if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) &&
13761376
tu->last_resolution != resolution) {
13771377
r1.event = SNDRV_TIMER_EVENT_RESOLUTION;
1378-
r1.tstamp = tstamp;
1378+
r1.tstamp = timespec64_to_timespec(tstamp);
13791379
r1.val = resolution;
13801380
snd_timer_user_append_to_tqueue(tu, &r1);
13811381
tu->last_resolution = resolution;
@@ -1389,14 +1389,14 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
13891389
prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1;
13901390
r = &tu->tqueue[prev];
13911391
if (r->event == SNDRV_TIMER_EVENT_TICK) {
1392-
r->tstamp = tstamp;
1392+
r->tstamp = timespec64_to_timespec(tstamp);
13931393
r->val += ticks;
13941394
append++;
13951395
goto __wake;
13961396
}
13971397
}
13981398
r1.event = SNDRV_TIMER_EVENT_TICK;
1399-
r1.tstamp = tstamp;
1399+
r1.tstamp = timespec64_to_timespec(tstamp);
14001400
r1.val = ticks;
14011401
snd_timer_user_append_to_tqueue(tu, &r1);
14021402
append++;
@@ -1885,7 +1885,7 @@ static int snd_timer_user_status(struct file *file,
18851885
if (!tu->timeri)
18861886
return -EBADFD;
18871887
memset(&status, 0, sizeof(status));
1888-
status.tstamp = tu->tstamp;
1888+
status.tstamp = timespec64_to_timespec(tu->tstamp);
18891889
status.resolution = snd_timer_resolution(tu->timeri);
18901890
status.lost = tu->timeri->lost;
18911891
status.overrun = tu->overrun;

‎sound/drivers/aloop.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ static void loopback_snd_timer_tasklet(unsigned long arg)
804804

805805
static void loopback_snd_timer_event(struct snd_timer_instance *timeri,
806806
int event,
807-
struct timespec *tstamp,
807+
struct timespec64 *tstamp,
808808
unsigned long resolution)
809809
{
810810
/* Do not lock cable->lock here because timer->lock is already hold.

‎sound/pci/hda/hda_controller.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static inline bool is_link_time_supported(struct snd_pcm_runtime *runtime,
491491
}
492492

493493
static int azx_get_time_info(struct snd_pcm_substream *substream,
494-
struct timespec *system_ts, struct timespec *audio_ts,
494+
struct timespec64 *system_ts, struct timespec64 *audio_ts,
495495
struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
496496
struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
497497
{
@@ -511,7 +511,7 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,
511511
if (audio_tstamp_config->report_delay)
512512
nsec = azx_adjust_codec_delay(substream, nsec);
513513

514-
*audio_ts = ns_to_timespec(nsec);
514+
*audio_ts = ns_to_timespec64(nsec);
515515

516516
audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
517517
audio_tstamp_report->accuracy_report = 1; /* rest of structure is valid */
@@ -528,16 +528,16 @@ static int azx_get_time_info(struct snd_pcm_substream *substream,
528528
return -EINVAL;
529529

530530
case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
531-
*system_ts = ktime_to_timespec(xtstamp.sys_monoraw);
531+
*system_ts = ktime_to_timespec64(xtstamp.sys_monoraw);
532532
break;
533533

534534
default:
535-
*system_ts = ktime_to_timespec(xtstamp.sys_realtime);
535+
*system_ts = ktime_to_timespec64(xtstamp.sys_realtime);
536536
break;
537537

538538
}
539539

540-
*audio_ts = ktime_to_timespec(xtstamp.device);
540+
*audio_ts = ktime_to_timespec64(xtstamp.device);
541541

542542
audio_tstamp_report->actual_type =
543543
SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK_SYNCHRONIZED;

‎sound/soc/intel/skylake/skl-pcm.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ static u64 skl_adjust_codec_delay(struct snd_pcm_substream *substream,
12581258
static int skl_platform_soc_get_time_info(
12591259
struct snd_soc_component *component,
12601260
struct snd_pcm_substream *substream,
1261-
struct timespec *system_ts, struct timespec *audio_ts,
1261+
struct timespec64 *system_ts, struct timespec64 *audio_ts,
12621262
struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
12631263
struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
12641264
{
@@ -1276,7 +1276,7 @@ static int skl_platform_soc_get_time_info(
12761276
if (audio_tstamp_config->report_delay)
12771277
nsec = skl_adjust_codec_delay(substream, nsec);
12781278

1279-
*audio_ts = ns_to_timespec(nsec);
1279+
*audio_ts = ns_to_timespec64(nsec);
12801280

12811281
audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
12821282
audio_tstamp_report->accuracy_report = 1; /* rest of struct is valid */

0 commit comments

Comments
 (0)