From patchwork Tue Sep 15 15:49:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 7187871 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5CCDE9F336 for ; Tue, 15 Sep 2015 15:55:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E783206E2 for ; Tue, 15 Sep 2015 15:55:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9203F206CC for ; Tue, 15 Sep 2015 15:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753218AbbIOPww (ORCPT ); Tue, 15 Sep 2015 11:52:52 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:55970 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753375AbbIOPtf (ORCPT ); Tue, 15 Sep 2015 11:49:35 -0400 Received: from wuerfel.lan. ([149.172.15.242]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0LbgPT-1YsbFd35NT-00lAhJ; Tue, 15 Sep 2015 17:49:26 +0200 From: Arnd Bergmann To: linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org, y2038@lists.linaro.org, Mauro Carvalho Chehab , linux-api@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Arnd Bergmann Subject: [PATCH 1/7] [media] dvb: use ktime_t for internal timeout Date: Tue, 15 Sep 2015 17:49:02 +0200 Message-Id: <1442332148-488079-2-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.1.0.rc2 In-Reply-To: <1442332148-488079-1-git-send-email-arnd@arndb.de> References: <1442332148-488079-1-git-send-email-arnd@arndb.de> X-Provags-ID: V03:K0:kac9V6AKe1haR4l8iZM+Cbe4a7dMtXK2TbtNErz27zyoPeMegVl VN6XgQE655EW5LRCl0IuwE4NFH59Ab2cfuCH/iT8Vuxff4skmpRXIysyRXmI3LH5agHq6NS dekQfmKBsfbNHUs/bkDbpdzy/GYNZ2nx9ifF5bM/Y7hF6kKY+g1J/c4IQr2YrYJFfn57aFp Ay3Rq7FE2mBmro2y0tcDQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:2eG81r6Nf5g=:NzpbRlxVoQQYvd9uv/cIPb nAJQZm2TnQ3q5k6bEFYuR7VfGe5mdLtOaCm1PBFTnq1uHV3ZqkRMLiWxc8qpyt3W148FwPPyN hpaBrWda3ajzqCAlGPX8ck5yYPyyU6MIn8amdqs2cncOqV1/pYhs9wYLc7u95k7pFIxjhDQhe KXr4ob+pKXsGE8nXDPTrtzuGw2XAulw2nLB86aMyeXju5G01eAC38YmUxTDfFLo3K6nwStGjH /uX406DE8hk/eURs1fHhAQQatvLKsRMuuLgnAxUHIK6OMhWTFGEQY8Kc8HbGtVzQTUft3DKJS v21PS8yFwC3YkEIcKxksz0pYvtUBCpEF81q+BHdae4GCClo91L6MT/VikYcWBr68VBEvtDYCX 5C5cQuOZPkhP+YKLNuD2n127x5tORdoDjWYpG8x9m2rvpF2K4GJBAd1mGF/jfDPAJKl7QlXq4 ip7RHHQMLdCgjcXMBxzXeWdteFs8iZJ8zf/Rrp34PJ+H8iK5l7LqCjMREw3CFYUxtcm0vM9T9 sJa0OJFQwYB6wjRHRQUr2CWAZYQ/IGh8ddrYCv8cPOLqq8fzzQWRT2bEpzV+MZD6jSyQl+4HZ H0KJsXl7Ft9fu/lsrjkWZms37HagWOJ8YvxhQP70vZT0O2iHlkL5RDhkljD6nteM77BpI58fp Xd8Ue6wSbbPPgj5CJ4nugwKGmpAma0krIuJDhX5zbgS8gTTCI7D2GmECMm2H4Vye246M= Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The dvb demuxer code uses a 'struct timespec' to pass a timeout as absolute time. This will cause problems on 32-bit architectures in 2038 when time_t overflows, and it is racy with a concurrent settimeofday() call. This patch changes the code to use ktime_get() instead, using the monotonic time base to avoid both the race and the overflow. Signed-off-by: Arnd Bergmann --- drivers/media/dvb-core/demux.h | 2 +- drivers/media/dvb-core/dmxdev.c | 2 +- drivers/media/dvb-core/dvb_demux.c | 17 ++++++----------- drivers/media/dvb-core/dvb_demux.h | 4 ++-- drivers/media/dvb-core/dvb_net.c | 2 +- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/media/dvb-core/demux.h b/drivers/media/dvb-core/demux.h index 833191bcd810..d8e2b1213bef 100644 --- a/drivers/media/dvb-core/demux.h +++ b/drivers/media/dvb-core/demux.h @@ -92,7 +92,7 @@ struct dmx_ts_feed { int type, enum dmx_ts_pes pes_type, size_t circular_buffer_size, - struct timespec timeout); + ktime_t timeout); int (*start_filtering) (struct dmx_ts_feed* feed); int (*stop_filtering) (struct dmx_ts_feed* feed); }; diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c index d0e3f9d85f34..0d20b379eeec 100644 --- a/drivers/media/dvb-core/dmxdev.c +++ b/drivers/media/dvb-core/dmxdev.c @@ -558,7 +558,7 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev, struct dmxdev_filter *filter, struct dmxdev_feed *feed) { - struct timespec timeout = { 0 }; + ktime_t timeout = ktime_set(0, 0); struct dmx_pes_filter_params *para = &filter->params.pes; dmx_output_t otype; int ret; diff --git a/drivers/media/dvb-core/dvb_demux.c b/drivers/media/dvb-core/dvb_demux.c index 6c7ff0cdcd32..d83dd0eb5757 100644 --- a/drivers/media/dvb-core/dvb_demux.c +++ b/drivers/media/dvb-core/dvb_demux.c @@ -399,28 +399,23 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf) int dvr_done = 0; if (dvb_demux_speedcheck) { - struct timespec cur_time, delta_time; + ktime_t cur_time; u64 speed_bytes, speed_timedelta; demux->speed_pkts_cnt++; /* show speed every SPEED_PKTS_INTERVAL packets */ if (!(demux->speed_pkts_cnt % SPEED_PKTS_INTERVAL)) { - cur_time = current_kernel_time(); + cur_time = ktime_get(); - if (demux->speed_last_time.tv_sec != 0 && - demux->speed_last_time.tv_nsec != 0) { - delta_time = timespec_sub(cur_time, - demux->speed_last_time); + if (ktime_to_ns(demux->speed_last_time) == 0) { speed_bytes = (u64)demux->speed_pkts_cnt * 188 * 8; /* convert to 1024 basis */ speed_bytes = 1000 * div64_u64(speed_bytes, 1024); - speed_timedelta = - (u64)timespec_to_ns(&delta_time); - speed_timedelta = div64_u64(speed_timedelta, - 1000000); /* nsec -> usec */ + speed_timedelta = ktime_ms_delta(cur_time, + demux->speed_last_time); printk(KERN_INFO "TS speed %llu Kbits/sec \n", div64_u64(speed_bytes, speed_timedelta)); @@ -667,7 +662,7 @@ out: static int dmx_ts_feed_set(struct dmx_ts_feed *ts_feed, u16 pid, int ts_type, enum dmx_ts_pes pes_type, - size_t circular_buffer_size, struct timespec timeout) + size_t circular_buffer_size, ktime_t timeout) { struct dvb_demux_feed *feed = (struct dvb_demux_feed *)ts_feed; struct dvb_demux *demux = feed->demux; diff --git a/drivers/media/dvb-core/dvb_demux.h b/drivers/media/dvb-core/dvb_demux.h index ae7fc33c3231..5ed3cab4ad28 100644 --- a/drivers/media/dvb-core/dvb_demux.h +++ b/drivers/media/dvb-core/dvb_demux.h @@ -83,7 +83,7 @@ struct dvb_demux_feed { u8 *buffer; int buffer_size; - struct timespec timeout; + ktime_t timeout; struct dvb_demux_filter *filter; int ts_type; @@ -134,7 +134,7 @@ struct dvb_demux { uint8_t *cnt_storage; /* for TS continuity check */ - struct timespec speed_last_time; /* for TS speed check */ + ktime_t speed_last_time; /* for TS speed check */ uint32_t speed_pkts_cnt; /* for TS speed check */ }; diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c index b81e026edab3..df3ba15c007e 100644 --- a/drivers/media/dvb-core/dvb_net.c +++ b/drivers/media/dvb-core/dvb_net.c @@ -998,7 +998,7 @@ static int dvb_net_feed_start(struct net_device *dev) netdev_dbg(dev, "start filtering\n"); priv->secfeed->start_filtering(priv->secfeed); } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) { - struct timespec timeout = { 0, 10000000 }; // 10 msec + ktime_t timeout = ns_to_ktime(10 * NSEC_PER_MSEC); /* we have payloads encapsulated in TS */ netdev_dbg(dev, "alloc tsfeed\n");