1 // SPDX-License-Identifier: GPL-2.0
3 * The Virtual DVB test driver serves as a reference DVB driver and helps
4 * validate the existing APIs in the media subsystem. It can also aid
5 * developers working on userspace applications.
7 * Copyright (C) 2020 Daniel W. S. Almeida
9 #define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
11 #include <linux/printk.h>
12 #include <linux/ratelimit.h>
13 #include <linux/string.h>
14 #include <linux/types.h>
16 #include "vidtv_common.h"
19 * vidtv_memcpy() - wrapper routine to be used by MPEG-TS
20 * generator, in order to avoid going past the
22 * @to: Starting element to where a MPEG-TS packet will
24 * @to_offset: Starting position of the @to buffer to be filled.
25 * @to_size: Size of the @to buffer.
26 * @from: Starting element of the buffer to be copied.
27 * @len: Number of elements to be copy from @from buffer
28 * into @to+ @to_offset buffer.
31 * Real digital TV demod drivers should not have memcpy
32 * wrappers. We use it here because emulating MPEG-TS
33 * generation at kernelspace requires some extra care.
36 * Returns the number of bytes written
38 u32
vidtv_memcpy(void *to
,
44 if (unlikely(to_offset
+ len
> to_size
)) {
45 pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %zu, had %zu\n",
51 memcpy(to
+ to_offset
, from
, len
);
56 * vidtv_memset() - wrapper routine to be used by MPEG-TS
57 * generator, in order to avoid going past the
59 * @to: Starting element to set
60 * @to_offset: Starting position of the @to buffer to be filled.
61 * @to_size: Size of the @to buffer.
62 * @c: The value to set the memory to.
63 * @len: Number of elements to be copy from @from buffer
64 * into @to+ @to_offset buffer.
67 * Real digital TV demod drivers should not have memset
68 * wrappers. We use it here because emulating MPEG-TS
69 * generation at kernelspace requires some extra care.
72 * Returns the number of bytes written
74 u32
vidtv_memset(void *to
,
80 if (unlikely(to_offset
+ len
> to_size
)) {
81 pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %zu, had %zu\n",
87 memset(to
+ to_offset
, c
, len
);