Commit Graph

100 Commits

Author SHA1 Message Date
Kent Overstreet fc09b4919c media: vidtv: fix missing include
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-18 00:23:10 -05:00
Jiasheng Jiang 1fd6eb1264 media: vidtv: mux: Add check and kfree for kstrdup
Add check for the return value of kstrdup() and return the error
if it fails in order to avoid NULL pointer dereference.
Moreover, use kfree() in the later error handling in order to avoid
memory leak.

Fixes: c2f78f0cb2 ("media: vidtv: psi: add a Network Information Table (NIT)")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
2023-10-07 10:55:45 +02:00
Jiasheng Jiang 76a2c5df6c media: vidtv: psi: Add check for kstrdup
Add check for the return value of kstrdup() and return the error
if it fails in order to avoid NULL pointer dereference.

Fixes: 7a7899f6f5 ("media: vidtv: psi: Implement an Event Information Table (EIT)")
Fixes: c2f78f0cb2 ("media: vidtv: psi: add a Network Information Table (NIT)")
Fixes: f90cf6079b ("media: vidtv: add a bridge driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
2023-10-07 10:55:45 +02:00
Uwe Kleine-König aaeb31c00e media: Switch i2c drivers back to use .probe()
After commit b8a1a4cd5a ("i2c: Provide a temporary .probe_new()
call-back type"), all drivers being converted to .probe_new() and then
commit 03c835f498 ("i2c: Switch .probe() to not take an id parameter")
convert back to (the new) .probe() to be able to eventually drop
.probe_new() from struct i2c_driver.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
2023-05-25 16:21:21 +02:00
Uwe Kleine-König b8b615b530 media: vidtv_bridge: Convert to platform remove callback returning void
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
2023-04-11 16:59:21 +02:00
Colin Ian King 3ef5750989 media: vidtv: make const array DURATION static
Don't populate the read-only const array DURATION on the stack but
instead make it static. Also makes the object code a little smaller.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2023-02-08 07:27:14 +01:00
Linus Torvalds cdb9d35377 media updates for v6.2-rc1
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEE+QmuaPwR3wnBdVwACF8+vY7k4RUFAmOW44IACgkQCF8+vY7k
 4RWt2RAAnUPY7bj2DDGo5rJ54KjMXhz6usdOnh9Hzg5eegGzK2xXAOyKVg4AFsNk
 rXWkbEc5Rg2LJnMZg8dojsG/utOV+xtCidQCYdhUKLPDREDMjSuUy/vs3utllwkg
 MhO8JDY+OQHhqXaMFRz0suGvr1W4kDmRR7+4VciEEPX9k9CX+FMYnuVlNyxLZG03
 Hu/PSDC4ltU+P0xnLap3U681PWfUDAoSvhyQmvde39EspSBxzFTVy7Cw1VL7DvwQ
 Idrcxo37buGf8eF9Em02PBgzC00TV6yCy5wOPOemcozBgtDSeLSQjlUUaOqHZgKI
 uY4k8LI0efnJPWIqt/rGZ4OREK+m7RbyAKvQ/9ckblm3bjsJV/T8WGtnNHxDRBVD
 ypoSvFyJ+RU6eFUw2jG61Fx0vPocK8AGnQLK860ns52h5DxyxpPxWtvPyNZLNs59
 bjZPetbU7bgvGZ8aBJno84Q+4Bliel8zXWnQKrAV28gjwCt/q/Lbd9G7sUYCZwIE
 EMxcOP9r2J1Q8zQK6s9xdZx2lRINWD+9Hgh1toS2KGhkAtT5BWyBmD2MXqt88v04
 8MeyneYt6uiv5Lst41BhxT/hvIyFb9g3pW28TAUCPV9r5pjyJVRNvPjJEv6dnR2e
 eRmBHcyLG6/Q1Do+HY2DjjgOsAL7yDxQJNahqFM/cFGYMVmYNFU=
 =i0X1
 -----END PGP SIGNATURE-----

Merge tag 'media/v6.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media

Pull media updates from Mauro Carvalho Chehab:

 - DVB core changes to avoid refcount troubles and UAF

 - DVB API/core has gained support for DVB-C2 and DVB-S2X

 - New sensor drivers: ov08x40, ov4689.c, st-vgxy61 and tc358746.c

 - Removal of an unused sensor driver: s5k4ecgx

 - Move microchip_csi2dc to a new directory, named after the
   manufacturer

 - Add media controller support to Microship drivers

 - Old Atmel/Microship drivers that don't use media controler got moved
   to staging

 - New drivers added for Renesas RZ/G2L CRU and MIPI CSI-2 support

 - Allwinner A31 camera sensor driver code was now split into a bridge
   and a separate processor driver

 - Added a virtual stateless decoder driver in order to test core
   support for stateless drivers and test userspace apps using it

 - removed platform-based support for ov9650, as this is not used
   anymore

 - atomisp now uses videobuf2 and supports normal mmap mode

 - the imx7-media-csi driver got promoted from staging

 - rcar-vin driver has gained support for gen3 UDS (Up Down Scaler)

 - most i2c drivers now use I2C .probe_new() kAPI

 - lots of drivers fixes, cleanups and improvements

* tag 'media/v6.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (544 commits)
  media: s5c73m3: Switch to GPIO descriptors
  media: i2c: s5k5baf: switch to using gpiod API
  media: i2c: s5k6a3: switch to using gpiod API
  media: imx: remove code for non-existing config IMX_GPT_ICAP
  media: si470x: Fix use-after-free in si470x_int_in_callback()
  media: staging: stkwebcam: Restore MEDIA_{USB,CAMERA}_SUPPORT dependencies
  media: coda: Add check for kmalloc
  media: coda: Add check for dcoda_iram_alloc
  dt-bindings: media: s5c73m3: Fix reset-gpio descriptor
  media: dt-bindings: allwinner: h6-vpu-g2: Add IOMMU reference property
  media: s5k4ecgx: Delete driver
  media: s5k4ecgx: Switch to GPIO descriptors
  media: Switch to use dev_err_probe() helper
  headers: Remove some left-over license text in include/uapi/linux/v4l2-*
  headers: Remove some left-over license text in include/uapi/linux/dvb/
  media: usb: pwc-uncompress: Use flex array destination for memcpy()
  media: s5p-mfc: Fix to handle reference queue during finishing
  media: s5p-mfc: Clear workbit to handle error condition
  media: s5p-mfc: Fix in register read and write for H264
  media: imx: Use get_mbus_config instead of parsing upstream DT endpoints
  ...
2022-12-13 11:36:58 -08:00
Mauro Carvalho Chehab 54607f29a2 Tag branch
-----BEGIN PGP SIGNATURE-----
 
 iHUEABYIAB0WIQRSrcquik9wuZrNjXJrQl33mxwedgUCY3toaQAKCRBrQl33mxwe
 dpoQAP4r5trvhHqB/9BLDYn+AwnXOewgywAoD8zBPntAL/WuBwD9HGmnwpJhGdXU
 ImIEVNqjGmH9gLJjqNHPm4t4YvxgBAg=
 =ZV3Y
 -----END PGP SIGNATURE-----

Merge tag 'br-v6.2g' of git://linuxtv.org/hverkuil/media_tree into media_stage

Despite being big, the changes here are trivial: they just change the
probing method for I2C. So, apply it as a merge.

Tag branch

* tag 'br-v6.2g' of git://linuxtv.org/hverkuil/media_tree: (96 commits)
  media: v4l2-core/tuner-core: Convert to i2c's .probe_new()
  media: usb: go7007: s2250-board: Convert to i2c's .probe_new()
  media: tuners/tua9001: Convert to i2c's .probe_new()
  media: tuners/tda18250: Convert to i2c's .probe_new()
  media: tuners/tda18212: Convert to i2c's .probe_new()
  media: tuners/qm1d1c0042: Convert to i2c's .probe_new()
  media: tuners/qm1d1b0004: Convert to i2c's .probe_new()
  media: tuners/mxl301rf: Convert to i2c's .probe_new()
  media: tuners/mt2060: Convert to i2c's .probe_new()
  media: tuners/m88rs6000t: Convert to i2c's .probe_new()
  media: tuners/fc2580: Convert to i2c's .probe_new()
  media: tuners/e4000: Convert to i2c's .probe_new()
  media: vidtv: Convert to i2c's .probe_new()
  media: radio/tef6862: Convert to i2c's .probe_new()
  media: radio/saa7706h: Convert to i2c's .probe_new()
  media: radio/radio-tea5764: Convert to i2c's .probe_new()
  media: i2c/wm8775: Convert to i2c's .probe_new()
  media: i2c/wm8739: Convert to i2c's .probe_new()
  media: i2c/vs6624: Convert to i2c's .probe_new()
  media: i2c/vpx3220: Convert to i2c's .probe_new()
  ...

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-11-25 07:55:21 +00:00
Chen Zhongjin 675807dee3 media: vidtv: Fix use-after-free in vidtv_bridge_dvb_init()
KASAN reports a use-after-free:
BUG: KASAN: use-after-free in dvb_dmxdev_release+0x4d5/0x5d0 [dvb_core]
Call Trace:
 ...
 dvb_dmxdev_release+0x4d5/0x5d0 [dvb_core]
 vidtv_bridge_probe+0x7bf/0xa40 [dvb_vidtv_bridge]
 platform_probe+0xb6/0x170
 ...
Allocated by task 1238:
 ...
 dvb_register_device+0x1a7/0xa70 [dvb_core]
 dvb_dmxdev_init+0x2af/0x4a0 [dvb_core]
 vidtv_bridge_probe+0x766/0xa40 [dvb_vidtv_bridge]
 ...
Freed by task 1238:
 dvb_register_device+0x6d2/0xa70 [dvb_core]
 dvb_dmxdev_init+0x2af/0x4a0 [dvb_core]
 vidtv_bridge_probe+0x766/0xa40 [dvb_vidtv_bridge]
 ...

It is because the error handling in vidtv_bridge_dvb_init() is wrong.

First, vidtv_bridge_dmx(dev)_init() will clean themselves when fail, but
goto fail_dmx(_dev): calls release functions again, which causes
use-after-free.

Also, in fail_fe, fail_tuner_probe and fail_demod_probe, j = i will cause
out-of-bound when i finished its loop (i == NUM_FE). And the loop
releasing is wrong, although now NUM_FE is 1 so it won't cause problem.

Fix this by correctly releasing everything.

Fixes: f90cf6079b ("media: vidtv: add a bridge driver")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-11-25 07:33:14 +00:00
Uwe Kleine-König 7d4833b166 media: vidtv: Convert to i2c's .probe_new()
The probe functions doesn't make use of the i2c_device_id * parameter so it
can be trivially converted.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
2022-11-21 11:04:42 +01:00
Jason A. Donenfeld 8032bf1233 treewide: use get_random_u32_below() instead of deprecated function
This is a simple mechanical transformation done by:

@@
expression E;
@@
- prandom_u32_max
+ get_random_u32_below
  (E)

Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
Reviewed-by: SeongJae Park <sj@kernel.org> # for damon
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> # for infiniband
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> # for arm
Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2022-11-18 02:15:15 +01:00
Uwe Kleine-König ed5c2f5fd1 i2c: Make remove callback return void
The value returned by an i2c driver's remove function is mostly ignored.
(Only an error message is printed if the value is non-zero that the
error is ignored.)

So change the prototype of the remove function to return no value. This
way driver authors are not tempted to assume that passing an error to
the upper layer is a good idea. All drivers are adapted accordingly.
There is no intended change of behaviour, all callbacks were prepared to
return 0 before.

Reviewed-by: Peter Senna Tschudin <peter.senna@gmail.com>
Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Benjamin Mugnier <benjamin.mugnier@foss.st.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Crt Mori <cmo@melexis.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Marek Behún <kabel@kernel.org> # for leds-turris-omnia
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Machata <petrm@nvidia.com> # for mlxsw
Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com> # for surface3_power
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> # for bmc150-accel-i2c + kxcjk-1013
Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> # for media/* + staging/media/*
Acked-by: Miguel Ojeda <ojeda@kernel.org> # for auxdisplay/ht16k33 + auxdisplay/lcd2s
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> # for versaclock5
Reviewed-by: Ajay Gupta <ajayg@nvidia.com> # for ucsi_ccg
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> # for iio
Acked-by: Peter Rosin <peda@axentia.se> # for i2c-mux-*, max9860
Acked-by: Adrien Grassein <adrien.grassein@gmail.com> # for lontium-lt8912b
Reviewed-by: Jean Delvare <jdelvare@suse.de> # for hwmon, i2c-core and i2c/muxes
Acked-by: Corey Minyard <cminyard@mvista.com> # for IPMI
Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> # for drivers/power
Acked-by: Krzysztof Hałasa <khalasa@piap.pl>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
2022-08-16 12:46:26 +02:00
Yihao Han 298cf3dfac media: vidtv: use vfree() for memory allocated with vzalloc()
It is allocated with vzalloc(), the corresponding release function
should not be kfree(), use vfree() instead.

Generated by: scripts/coccinelle/api/kfree_mismatch.cocci

Signed-off-by: Yihao Han <hanyihao@vivo.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-03-18 07:28:17 +01:00
Mauro Carvalho Chehab 6cdc31b2d7 media: media/*/Kconfig: sort entries
Currently, the idems inside media Kconfig are out of order.
Sort them using the script below:

<script>
use strict;
use warnings;

my %config;
my @source;
my $out;

sub flush_config()
{
	if (scalar %config) {
		for my $c (sort keys %config) {
			$out .= $config{$c} . "\n";
		}
		%config = ();
	}

	return if (!scalar @source);

	$out .= "\n";
	for my $s (sort @source) {
		$out .= $s;
	}
	$out .= "\n";

	@source = ();
}

sub sort_kconfig($)
{
	my $fname = shift;
	my $cur_config = "";

	@source = ();
	$out = "";
	%config = ();

	open IN, $fname or die;
	while (<IN>) {
		if (m/^config\s+(.*)/) {
			$cur_config = $1;
			$config{$cur_config} .= $_;
		} elsif (m/^source\s+(.*)/) {
			push @source, $_;
		} elsif (m/^\s+/) {
			if ($cur_config eq "") {
				$out .= $_;
			} else {
				$config{$cur_config} .= $_;
			}
		} else {
			flush_config();
			$cur_config = "";
			$out .= $_;
		}
	}
	close IN or die;

	flush_config();

	$out =~ s/\n\n+/\n\n/g;
	$out =~ s/\n+$/\n/;

	open OUT, ">$fname";
	print OUT $out;
	close OUT;
}

for my $fname(@ARGV) {
	sort_kconfig $fname
}
</script>

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-03-18 05:58:35 +01:00
Jiasheng Jiang e6a21a1410 media: vidtv: Check for null return of vzalloc
As the possible failure of the vzalloc(), e->encoder_buf might be NULL.
Therefore, it should be better to check it in order
to guarantee the success of the initialization.
If fails, we need to free not only 'e' but also 'e->name'.
Also, if the allocation for ctx fails, we need to free 'e->encoder_buf'
else.

Fixes: f90cf6079b ("media: vidtv: add a bridge driver")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
2022-03-07 11:06:19 +01:00
Minghao Chi 9dd2444f23 media: vidtv: remove unneeded variable make code cleaner
return value form directly instead of
taking this in another redundant variable.

Link: https://lore.kernel.org/linux-media/20211210024721.425145-1-chi.minghao@zte.com.cn
Reported-by: Zeal Robot <zealci@zte.com.cm>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-12-14 16:19:04 +01:00
Hans Verkuil 112024a3b6 media: vidtv: move kfree(dvb) to vidtv_bridge_dev_release()
Adding kfree(dvb) to vidtv_bridge_remove() will remove the memory
too soon: if an application still has an open filehandle to the device
when the driver is unloaded, then when that filehandle is closed, a
use-after-free access takes place to the freed memory.

Move the kfree(dvb) to vidtv_bridge_dev_release() instead.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Fixes: 76e21bb8be ("media: vidtv: Fix memory leak in remove")
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-10-19 08:08:19 +01:00
Evgeny Novikov 76e21bb8be media: vidtv: Fix memory leak in remove
vidtv_bridge_remove() releases and cleans up everything except for dvb
itself. The patch adds this missed release.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-09-30 10:07:53 +02:00
Zhang Yunkai 1b0b433fd1 media: vidtv: remove duplicate include in vidtv_psi
'string.h' included in 'vidtv_psi.c' is duplicated.

Signed-off-by: Zhang Yunkai <zhang.yunkai@zte.com.cn>
Acked-by: Daniel Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-03-22 10:20:02 +01:00
Hans Verkuil c90c103c8d media: vidtv: adapter->mdev was set too late
The media device has to be initialized and assigned to adapter->mdev
before the dvb devices are created, since that will trigger the
automatic creation of the topology.

Rework this code to achieve this.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-02-05 23:52:58 +01:00
Daniel W. S. Almeida ed35980a4d media: vidtv: print message when driver is removed
Print a message when the driver is removed so that we get some
visual confirmation when unbinding vidtv.

Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-01-27 12:29:37 +01:00
Daniel W. S. Almeida 0b8f1d4a09 media: vidtv: use a simpler name in platform_{device|driver}
Change from "vidtv_bridge" to simply "vidtv" so that vidtv looks
more similar to the other media virtual drivers in /sys/bus/platform.

Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-01-27 12:29:17 +01:00
Daniel W. S. Almeida 707848ccdf media: vidtv: reinstate sysfs bind attrs
Reinstate sysfs bind attrs so that vidtv can be bound and unbound
via sysfs. This is useful for automated regression testing in
userspace.

Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-01-27 12:28:43 +01:00
Daniel W. S. Almeida e259572d6f media: vidtv: Add media controller support
Add media controller support when CONFIG_MEDIA_CONTROLLER_DVB is set
so that, in the future, a test sequence in v4l-utils can be written
without having to know which /dev/fooX device should be used.

[mchehab: avoided usage of C99 comments]
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-01-27 12:28:18 +01:00
Tian Tao 8d23ada8e7 media: vidtv: Use kmemdup instead of kzalloc and memcpy
Fixes coccicheck warning:
drivers/media/test-drivers/vidtv/vidtv_psi.c:509:10-17: WARNING
opportunity for kmemdup

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-01-27 12:07:02 +01:00
Daniel W. S. Almeida 4671c204dd media: vidtv: remove unused field from 'struct vidtv_mpeg_ts'
Commit 3d1387b3b8 ("media: vidtv: fix some warnings") replaced
the unused flexible array member at the end of struct vidtv_mpeg_ts
with a pointer. This broke the 188-byte alignment since the struct
no longer was 4 bytes in size.

Fix this by removing this field entirely.

Fixes: 3d1387b3b8 ("media: vidtv: fix some warnings")
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-01-27 11:47:02 +01:00
Daniel W. S. Almeida 0a933a7f73 media: vidtv: psi: fix missing crc for PMT
The PMT write function was refactored and this broke the CRC computation.

Fix it.

Fixes: db9569f67e ("media: vidtv: cleanup PMT write table function")
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-01-27 11:45:57 +01:00
Mauro Carvalho Chehab 3d1387b3b8 media: vidtv: fix some warnings
As reported by sparse:

	drivers/media/test-drivers/vidtv/vidtv_ts.h:47:47: warning: array of flexible structures
	drivers/media/test-drivers/vidtv/vidtv_channel.c:458:54: warning: incorrect type in argument 3 (different base types)
	drivers/media/test-drivers/vidtv/vidtv_channel.c:458:54:    expected unsigned short [usertype] service_id
	drivers/media/test-drivers/vidtv/vidtv_channel.c:458:54:    got restricted __be16 [usertype] service_id
	drivers/media/test-drivers/vidtv/vidtv_s302m.c:471 vidtv_s302m_encoder_init() warn: possible memory leak of 'e'

Address such warnings.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-12-08 08:15:49 +01:00
Mauro Carvalho Chehab cc2ff9730e media: vidtv: fix kernel-doc markups
Some functions has a different name between their prototypes
and the corresponding kernel-doc markups.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-12-02 13:17:57 +01:00
Colin Ian King 3c0dde35e6 media: [next] media: vidtv: fix a read from an object after it has been freed
Currently the call to vidtv_psi_pat_table_destroy frees the object
m->si.pat however m->si.pat->num_pmt is being accessed after the
free.  Fix this by destroying m->si.pat after the m->si.pmt_secs[]
objects have been freed.

Addresses-Coverity: ("Read from pointer after free")

Reported-by: Cengiz Can <cengiz@kernel.wtf> # sent a similar fix about the same time

Fixes: 039b7caed1 ("media: vidtv: add a PID entry for the NIT table")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-12-02 13:15:07 +01:00
Mauro Carvalho Chehab 44f28934af media: vidtv.rst: add kernel-doc markups
Fix existing issues at the kernel-doc markups and add them to
the vidtv.rst file.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab b087982886 media: vidtv: simplify EIT write function
- pass struct vidtv_psi_eit_write_args as a pointer;
- avoid initializing struct fields multiple times.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab 5a5b9fb1a1 media: vidtv: simplify NIT write function
- pass struct vidtv_psi_nit_write_args as a pointer;
- avoid initializing struct fields multiple times.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab 6286a4b79b media: vidtv: simplify SDT write function
- pass struct vidtv_psi_sdt_write_args as a pointer;
- avoid initializing struct fields multiple times.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab db9569f67e media: vidtv: cleanup PMT write table function
- Pass struct vidtv_psi_pmt_write_args as a pointer;
- Avoid initializing structs multiple times.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab 7f95751519 media: vidtv: cleanup PAT write function
Avoid initializing the structs multiple times and pass the
PAT struct as a pointer, instead of a var.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab c570fb9ffc media: vidtv: cleanup PSI table header function
- Pass struct header_write_args as a pointer, instead of
  passing as a var;

- Initialize the psi_args struct only once.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab 974ea17692 media: vidtv: cleanup PSI descriptor write function
This function initializes the psi_args twice, and receives
a struct, instead of a pointer to a struct.

Clean it up.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab 9e0067417b media: vidtv: simplify the crc writing logic
Cleanup the table_section_crc32_write_into() function
by initializing struct psi_write_args only once and by
passing the args as a pointer.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab 5edbd330e3 media: vidtv: simplify PSI write function
The function vidtv_psi_ts_psi_write_into() initializes the
ts_header fields several times, and receives a struct
as argument, instead of using a pointer to struct.

Cleanup the function, in order to reduce its stack usage
and to avoid initializing the ts_header multiple times.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab 160028542b media: vidtv: add date to the current event
The current event is using an undefined date. Instead, it
should be the timestamp when the EIT table was generated.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:24 +01:00
Mauro Carvalho Chehab bfa4aaebe8 media: vidtv: fix service_id at SDT table
The service_id there should be equal to the one used
on other tables, otherwise, EIT entries won't be valid.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab 11f4933f7b media: vidtv: fix service type
As the service currently broadcasts just audio, change the
service type to reflect that.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab 039b7caed1 media: vidtv: add a PID entry for the NIT table
On normal TS streams, the NIT table has its own entry at PAT,
but not at PMT.

While here, properly handle alloc problems when creating
PMT entries.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab 91a8a240e2 media: vidtv: properly fill EIT service_id
The EIT header ID field should not contain the network ID, but,
instead, the service_id of the program described at EIT.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab 1d2b2a6d8c media: vidtv: fix the network ID range
As defined at ETSI TS 101 162, original network IDs up to 0xfebf
are reserved for registration at dvb.org.

Let's use, instead, an original network ID at the range
0xff00-0xffff, as this is for private temporary usage.

As the same value is also used for the network ID,
the range 0xff01-0xffff also fits better, as values
lower than that depend if the network is used for
satellite, terrestrial, cable of CI.

While here, move the TS ID to the bridge code, where it
is used, and change its value, as it was identical to
the value previously used by network ID. While we could
keep the same value, let's change it, just to make easier
to check for the new code while reading it with DVB tools
like dvbinspector.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab b9e09e06e3 media: vidtv: improve EIT data
Place some text at EIT data, and use ISO 8859-15 encoding for
the German letter "ü" (u mit umlat) letter.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab ec3eda53f4 media: vidtv: cleanup null packet initialization logic
Initialize the destination buffer/size and the initial
offset when creating the local var.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab c857b065ab media: vidtv: pre-initialize mux arrays
Instead of first zeroing all fields at the mux structs and
then filling, do some initialization for the const data
when they're created.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00
Mauro Carvalho Chehab 330d135679 media: vidtv: remove some unused functions
Right now, there's no need to access the length of some
tables. So, drop the unused functions.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2020-11-26 08:05:23 +01:00