![]() |
|
|||
0001 // SPDX-License-Identifier: GPL-2.0 0002 /* 0003 * The Virtual DVB test driver serves as a reference DVB driver and helps 0004 * validate the existing APIs in the media subsystem. It can also aid 0005 * developers working on userspace applications. 0006 * 0007 * Copyright (C) 2020 Daniel W. S. Almeida 0008 */ 0009 #define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__ 0010 0011 #include <linux/printk.h> 0012 #include <linux/ratelimit.h> 0013 #include <linux/string.h> 0014 #include <linux/types.h> 0015 0016 #include "vidtv_common.h" 0017 0018 /** 0019 * vidtv_memcpy() - wrapper routine to be used by MPEG-TS 0020 * generator, in order to avoid going past the 0021 * output buffer. 0022 * @to: Starting element to where a MPEG-TS packet will 0023 * be copied. 0024 * @to_offset: Starting position of the @to buffer to be filled. 0025 * @to_size: Size of the @to buffer. 0026 * @from: Starting element of the buffer to be copied. 0027 * @len: Number of elements to be copy from @from buffer 0028 * into @to+ @to_offset buffer. 0029 * 0030 * Note: 0031 * Real digital TV demod drivers should not have memcpy 0032 * wrappers. We use it here because emulating MPEG-TS 0033 * generation at kernelspace requires some extra care. 0034 * 0035 * Return: 0036 * Returns the number of bytes written 0037 */ 0038 u32 vidtv_memcpy(void *to, 0039 size_t to_offset, 0040 size_t to_size, 0041 const void *from, 0042 size_t len) 0043 { 0044 if (unlikely(to_offset + len > to_size)) { 0045 pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %zu, had %zu\n", 0046 to_offset + len, 0047 to_size); 0048 return 0; 0049 } 0050 0051 memcpy(to + to_offset, from, len); 0052 return len; 0053 } 0054 0055 /** 0056 * vidtv_memset() - wrapper routine to be used by MPEG-TS 0057 * generator, in order to avoid going past the 0058 * output buffer. 0059 * @to: Starting element to set 0060 * @to_offset: Starting position of the @to buffer to be filled. 0061 * @to_size: Size of the @to buffer. 0062 * @c: The value to set the memory to. 0063 * @len: Number of elements to be copy from @from buffer 0064 * into @to+ @to_offset buffer. 0065 * 0066 * Note: 0067 * Real digital TV demod drivers should not have memset 0068 * wrappers. We use it here because emulating MPEG-TS 0069 * generation at kernelspace requires some extra care. 0070 * 0071 * Return: 0072 * Returns the number of bytes written 0073 */ 0074 u32 vidtv_memset(void *to, 0075 size_t to_offset, 0076 size_t to_size, 0077 const int c, 0078 size_t len) 0079 { 0080 if (unlikely(to_offset + len > to_size)) { 0081 pr_err_ratelimited("overflow detected, skipping. Try increasing the buffer size. Needed %zu, had %zu\n", 0082 to_offset + len, 0083 to_size); 0084 return 0; 0085 } 0086 0087 memset(to + to_offset, c, len); 0088 return len; 0089 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |