Shuah Khan [Fri, 28 Feb 2014 21:23:02 +0000 (18:23 -0300)]
[media] drx-j: fix boot failure due to null pointer dereference
DJH_DEBUG only code path in drxbsp_i2c_write_read() dereferences
w_dev_addr and subsequently w_dev_addr->user_data->i2c which results
in failure during boot. This patch fixes the null pointer derefence
bug as well as the following compile errors:
LD arch/x86/built-in.o
CC drivers/media/dvb-frontends/drx39xyj/drxj.o
drivers/media/dvb-frontends/drx39xyj/drxj.c: In function ‘drxbsp_i2c_write_read’:
drivers/media/dvb-frontends/drx39xyj/drxj.c:1558:25: error: redeclaration of ‘state’ with no linkage
struct drx39xxj_state *state = w_dev_addr->user_data;
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:1512:25: note: previous declaration of ‘state’ was here
struct drx39xxj_state *state;
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:1558:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
struct drx39xxj_state *state = w_dev_addr->user_data;
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:1560:17: error: redeclaration of ‘msg’ with no linkage
struct i2c_msg msg[2] = {
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:1513:17: note: previous declaration of ‘msg’ was here
struct i2c_msg msg[2];
^
This file contains an abstract layer for the I2C transfer
functions. Get rid of it, merging it at drxj. This will allow
to remove another abstraction layer there, making the code
easier to read, and removing the functions that just return
-EIO.
[media] drx-j: use the proper timeout code on scu_command
Checking if a time is after another one can have issues, as
times are generally u32 wide.
Use the proper macros for that at scu_command().
It should be noticed that other places also use jiffies
calculus on an improper way. This should be fixed too,
but the logic there is more complex. So, let's do it in
separate patches.
When switching from one video standard to another one,
power_down_vsb is called twice. Well, as the device is already
in power_down mode, the second call always fail. This causes that
any subsequent frontend set to fail as well:
[145074.501243] drx39xyj:power_down_vsb: called
[145089.195396] drx39xyj:power_down_vsb: error -5
[145089.195404] drx39xyj:ctrl_set_standard: error -5
[145089.195417] drx39xyj:drx39xxj_set_frontend: Failed to set standard! result=fffffffb
[145089.195470] drx39xyj:ctrl_sig_quality: error -5
[145089.195473] drx39xyj:drx39xxj_read_ber: drx39xxj: could not get ber!
[145089.195475] drx39xyj:ctrl_sig_quality: error -5
[145089.195477] drx39xyj:drx39xxj_read_signal_strength: drx39xxj: could not get signal strength!
[145089.195479] drx39xyj:ctrl_sig_quality: error -5
[145089.195480] drx39xyj:drx39xxj_read_snr: drx39xxj: could not read snr!
[145089.195482] drx39xyj:ctrl_sig_quality: error -5
[145089.195484] drx39xyj:drx39xxj_read_ucblocks: drx39xxj: could not get uc blocks!
[145089.195498] drx39xyj:ctrl_sig_quality: error -5
[145089.195500] drx39xyj:drx39xxj_read_ber: drx39xxj: could not get ber!
[145089.195502] drx39xyj:ctrl_sig_quality: error -5
[145089.195503] drx39xyj:drx39xxj_read_signal_strength: drx39xxj: could not get signal strength!
[145089.195505] drx39xyj:ctrl_sig_quality: error -5
[145089.195506] drx39xyj:drx39xxj_read_snr: drx39xxj: could not read snr!
[145089.195508] drx39xyj:ctrl_sig_quality: error -5
[145089.195510] drx39xyj:drx39xxj_read_ucblocks: drx39xxj: could not get uc blocks!
[145090.196291] drx39xyj:drx39xxj_read_status: drx39xxj: could not get lock status!
[145090.196508] drx39xyj:ctrl_sig_quality: error -5
[145090.196511] drx39xyj:drx39xxj_read_ber: drx39xxj: could not get ber!
[145090.196514] drx39xyj:ctrl_sig_quality: error -5
[145090.196515] drx39xyj:drx39xxj_read_signal_strength: drx39xxj: could not get signal strength!
[145090.196518] drx39xyj:ctrl_sig_quality: error -5
[145090.196519] drx39xyj:drx39xxj_read_snr: drx39xxj: could not read snr!
[145090.196522] drx39xyj:ctrl_sig_quality: error -5
[145090.196523] drx39xyj:drx39xxj_read_ucblocks: drx39xxj: could not get uc blocks!
[145090.196553] drx39xyj:ctrl_sig_quality: error -5
[145090.196554] drx39xyj:drx39xxj_read_ber: drx39xxj: could not get ber!
[145090.196557] drx39xyj:ctrl_sig_quality: error -5
[145090.196558] drx39xyj:drx39xxj_read_signal_strength: drx39xxj: could not get signal strength!
[145090.196560] drx39xyj:ctrl_sig_quality: error -5
[145090.196562] drx39xyj:drx39xxj_read_snr: drx39xxj: could not read snr!
[145090.196564] drx39xyj:ctrl_sig_quality: error -5
[145090.196565] drx39xyj:drx39xxj_read_ucblocks: drx39xxj: could not get uc blocks!
[145091.119265] drx39xyj:ctrl_sig_quality: error -5
[145091.119271] drx39xyj:drx39xxj_read_ber: drx39xxj: could not get ber!
[145091.119274] drx39xyj:ctrl_sig_quality: error -5
[145091.119276] drx39xyj:drx39xxj_read_signal_strength: drx39xxj: could not get signal strength!
[145091.119278] drx39xyj:ctrl_sig_quality: error -5
[145091.119280] drx39xyj:drx39xxj_read_snr: drx39xxj: could not read snr!
[145091.119282] drx39xyj:ctrl_sig_quality: error -5
[145091.119283] drx39xyj:drx39xxj_read_ucblocks: drx39xxj: could not get uc blocks!
[media] drx-j: remove some ugly bindings from drx39xxj_dummy.c
This file does an ugly binding between drxj and DVB frontend.
Remove most of the functions there. We still need to get rid of
get_frequency and set_frequency, but such patch is a little more
complex, as it should also remove some previous tuner bindings.
In order to avoid warnings and to remove dead code, remove
the functions that don't make sense to happen, while commenting
the others that might still be useful some day.
That reduced a lot the text size:
Before:
text data bss dec hex filename
58419 2916 4 61339 ef9b drivers/media/dvb-frontends/drx39xyj/drx39xyj.ko
After:
text data bss dec hex filename
78331 2916 4 81251 13d63 drivers/media/dvb-frontends/drx39xyj/drx39xyj.ko
Without any functional changes.
It could be make sense latter to remove those drivers or to
move them into an analog-specific part of the driver.
With this change, we finally got rid of all abstraction
layers on this driver.
This patch also fixes the LNA GPIO settings, as the original
code were using a wrong control name for it.
This patch exposes the several functions that aren't used.
Some of them are related to analog demod that might be
used some day, but others will likely never be needed, as
they don't fit on Linux media APIs.
ClearQAM is currently not working. Add support for it too.
Unlikely other ATSC tuners, though, this device will not
auto-detect between ATSC and ClearQAM. So, the delivery
system should be properly set.
Also, this frontend seems to also support DVB-C annex A/C. Add
experimental support for them.
[media] drx-j: Split firmware size check from the main routine
The firmware upload routine is already complex enough. Split the
first loop that verifies the firmware size into a separate routine,
making the code more readable.
Instead of defining its own set of error codes, use the linux
native ones.
Please note that this patch made a "stupid" error code mapping, just
replacing the codes with the closest one. In special, -EIO is being
used on several places. I'm pretty sure this could be better assigned,
but a change like that would require lots o time and efforts, without
much benefit.
So lets do adjstments at the error codes latter, when we have more
time.
Fix almost all checkpatch.pl warnings/errors on drxj.c, except for:
- 80 cols whitespacing;
- too many leading tabs;
- a false positive at DRXJ_16TO8() macro.
- static char array declaration should probably be static const char
as adding "const" would cause warnings.
Using return and goto inside macros is ugly and makes harder to
understand the code and the labels. Remove those macros, and add
a proper error debug message, when something bad happens.
This was generated using the following coccinelle script:
[media] drx-j: Don't use buffer if an error occurs
drivers/media/dvb-frontends/drx39xyj/drxj.c: In function ‘drxj_dap_scu_atomic_read_reg16’:
drivers/media/dvb-frontends/drx39xyj/drxj.c:4170:9: warning: ‘*((void *)&buf+1)’ may be used uninitialized in this function [-Wmaybe-uninitialized]
word = (u16) (buf[0] + (buf[1] << 8));
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:4170:9: warning: ‘buf’ may be used uninitialized in this function [-Wmaybe-uninitialized]
drivers/media/dvb-frontends/drx39xyj/drxj.c: In function ‘drxj_dap_atomic_read_reg32.isra.59’:
drivers/media/dvb-frontends/drx39xyj/drxj.c:2186:7: warning: ‘*((void *)&buf+3)’ may be used uninitialized in this function [-Wmaybe-uninitialized]
word = (u32) buf[3];
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:2188:10: warning: ‘*((void *)&buf+2)’ may be used uninitialized in this function [-Wmaybe-uninitialized]
word |= (u32) buf[2];
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:2190:10: warning: ‘*((void *)&buf+1)’ may be used uninitialized in this function [-Wmaybe-uninitialized]
word |= (u32) buf[1];
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:2192:10: warning: ‘buf’ may be used uninitialized in this function [-Wmaybe-uninitialized]
word |= (u32) buf[0];
^
This were fixed with the help of this small perl script:
#!/usr/bin/perl
my $dir = shift or die "need a dir";
my $type = shift or die "need type";
my $var = shift or die "need var";
sub handle_file {
my $file = shift;
my $out;
open IN, $file or die "can't open $file";
$out .= $_ while (<IN>);
close IN;
$out =~ s/\btypedef\s+($type)\s+\{([\d\D]+?)\s*\}\s+\b($var)[^\;]+\;/$type $var \{\2\};/;
$out =~ s,\b($var)_t\s+,$type \1 ,g;
$out =~ s,\bp_*($var)_t\s+,$type \1 *,g;
$out =~ s,\b($var)_t\b,$type \1,g;
$out =~ s,\bp_*($var)_t\b,$type \1 *,g;
open OUT, ">$file" or die "can't open $file";
print OUT $out;
close OUT;
}
sub parse_dir {
my $file = $File::Find::name;
return if (!($file =~ /.[ch]$/));
handle_file $file;
}
find({wanted => \&parse_dir, no_chdir => 1}, $dir);
[media] drx-j: get rid of typedefs in drx_driver.h
Most of the changes were done with scripts like:
for i in drivers/media/dvb-frontends/drx39xyj/*.[ch]; do perl -ne '$var = "drx_sig_quality"; s,\b($var)_t\s+,struct \1 ,g; s,\bp_*($var)_t\s+,struct \1 *,g; s,\b($var)_t\b,struct \1,g; s,\bp_*($var)_t\b,struct \1 *,g; print $_' <$i >a && mv a $i; done
drivers/media/dvb-frontends/drx39xyj/drx_driver.c:181:7: warning: no previous prototype for 'get_scan_context' [-Wmissing-prototypes]
void *get_scan_context(pdrx_demod_instance_t demod, void *scan_context)
drivers/media/dvb-frontends/drx39xyj/drx_driver.c: At top level:
drivers/media/dvb-frontends/drx39xyj/drx_driver.c:842:5: warning: no previous prototype for 'ctrl_dump_registers' [-Wmissing-prototypes]
int ctrl_dump_registers(pdrx_demod_instance_t demod,
[media] drx-j: Remove a bunch of unused but assigned vars
None of those vars are used on those functions. Just remove them.
After this patch, there's just one of such warnings:
drivers/media/dvb-frontends/drx39xyj/drxj.c: In function 'ctrl_get_qam_sig_quality':
drivers/media/dvb-frontends/drx39xyj/drxj.c:7872:6: warning: variable 'ber_cnt' set but not used [-Wunused-but-set-variable]
u32 ber_cnt = 0; /* BER count */
We'll keep it, as BER count will be useful when converting the
frontend to report statistics via DVBv5 API
[media] drx-j: fix whitespacing on pointer parmameters
Patch generated with this script:
for i in drivers/media/dvb-frontends/drx39xyj/*.[ch]; do perl -ne 's,(enum|struct|void|int|u32|u64|u16|u8|s8|s16|s32|s64)\s+(\S+)\s+\*[ ]+,\1 \2 *,g; print $_' <$i >a && mv a $i; done
There are lots of typedefs there. Let's get rid of them.
Most of the work here is due to this small script:
if [ "$3" == "" ]; then
echo "usage: $0 type DRXName drx_name"
fi
t=$1; f=$2; g=$3
for i in *.[ch]; do
sed s,"p${f}_t","$t $g *",g <$i >a && mv a $i && \
sed s,"${f}_t","$t $g",g <$i >a && mv a $i
done
Just kept there the function typedefs, as those are still useful.
Yet, all those tuner_ops can likely be just removed on a latter
cleanup patch.
[media] drx-j: get rid of the other typedefs at bsp_types.h
Most of the work were done by those small scripts:
for i in *; do sed s,pDRXFrequency_t,"s32 *",g <$i >a && mv a $i; done
for i in *; do sed s,DRXFrequency_t,"s32",g <$i >a && mv a $i; done
for i in *; do sed s,pDRXSymbolrate_t,"u32 *",g <$i >a && mv a $i; done
for i in *; do sed s,DRXSymbolrate_t,"u32",g <$i >a && mv a $i; done
for i in *; do sed s,FALSE,false,g <$i >a && mv a $i; done
for i in *; do sed s,TRUE,true,g <$i >a && mv a $i; done
for i in *; do sed s,Bool_t,bool,g <$i >a && mv a $i; done
for i in *; do sed s,pbool,"bool *",g <$i >a && mv a $i; done
The only remaining things there are the return values.
for j in 8 16 32; do for i in *; do sed s,pu${j}_t,"u$j *",g <$i >a && mv a $i; done; done
for j in 8 16 32; do for i in *; do sed s,ps${j}_t,"s$j *",g <$i >a && mv a $i; done; done
for j in 8 16 32; do for i in *; do sed s,s${j}_t,"s$j",g <$i >a && mv a $i; done; done
for j in 8 16 32; do for i in *; do sed s,u${j}_t,"u$j",g <$i >a && mv a $i; done; done
[media] drx-j: remove the "const" annotate on HICommand()
After removing the typedef, it is now clear that HICommand() were
abusing of a var that was expecting to be constant:
drivers/media/dvb-frontends/drx39xyj/drxj.c: In function ‘HICommand’:
drivers/media/dvb-frontends/drx39xyj/drxj.c:2272:3: warning: passing argument 1 of ‘drxDapDRXJFunct_g.writeReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2272:3: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2273:3: warning: passing argument 1 of ‘drxDapDRXJFunct_g.writeReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2273:3: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2274:3: warning: passing argument 1 of ‘drxDapDRXJFunct_g.writeReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2274:3: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2275:3: warning: passing argument 1 of ‘drxDapDRXJFunct_g.writeReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2275:3: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2278:3: warning: passing argument 1 of ‘drxDapDRXJFunct_g.writeReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2278:3: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2279:3: warning: passing argument 1 of ‘drxDapDRXJFunct_g.writeReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2279:3: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2291:2: warning: passing argument 1 of ‘drxDapDRXJFunct_g.writeReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2291:2: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2311:4: warning: passing argument 1 of ‘drxDapDRXJFunct_g.readReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2311:4: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
drivers/media/dvb-frontends/drx39xyj/drxj.c:2315:3: warning: passing argument 1 of ‘drxDapDRXJFunct_g.readReg16Func’ discards ‘const’ qualifier from pointer target type [enabled by default]
drivers/media/dvb-frontends/drx39xyj/drxj.c:2315:3: note: expected ‘struct i2c_device_addr *’ but argument is of type ‘const struct i2c_device_addr *’
[media] drx-j: get rid of the typedefs on bsp_i2c.h
Most of the hard work here were done by this small script:
for i in *; do sed s,pI2CDeviceAddr_t,"struct i2c_device_addr *",g <$i >a && mv a $i; done
for i in *; do sed s,I2CDeviceAddr_t,"struct i2c_device_addr",g <$i >a && mv a $i; done
[media] drx-j: add a driver for Trident drx-j frontend
Add support for the Trident DRX-J driver, including a card profile for the
PCTV 80e which uses the chip.
Thanks to Trident for allowing the release of this code under a BSD license,
and of course Hauppauge/PCTV for pushing for its release to the community.
[pdickeybeta@gmail.com: modified to fix compilation errors and also to move
the driver files from the drx39xy subdirectory to the frontends directory]
[m.chehab@samsung.com: fix merge conflicts, commented drx-j compilation and
added EM28XX_R06_I2C_CLK setup also to the board setup]
Those ioctls were added back in 2009, at changeset 1cb662a3144
but were never documented. Fortunately, the original commit is
good enough to serve as the basis for documenting it. Also, the
support for it is done by dmxdev implementation.
So, add a proper documentation for it, based on the description
of the original changeset.
Implement em28xx_usb_driver suspend, resume, and reset_resume hooks.
These hooks will invoke em28xx core em28xx_suspend_extension() and
em28xx_resume_extension() to suspend and resume registered extensions.
Approach:
Add power management support to em28xx usb driver. This driver works in
conjunction with extensions for each of the functions on the USB device
for video/audio/dvb/remote functionality that is present on media USB
devices it supports. During suspend and resume each of these extensions
will have to do their part in suspending the components they control.
Adding suspend and resume hooks to the existing struct em28xx_ops will
enable the extensions the ability to implement suspend and resume hooks
to be called from em28xx driver. The overall approach is as follows:
-- add suspend and resume hooks to em28xx_ops
-- add suspend and resume routines to em28xx-core to invoke suspend
and resume hooks for all registered extensions.
-- change em28xx dvb, audio, input, and video extensions to implement
em28xx_ops: suspend and resume hooks. These hooks do what is necessary
to suspend and resume the devices they control.
Implement em28xx_ops: suspend/resume hooks. em28xx usb driver will
invoke em28xx_ops: suspend and resume hooks for all its extensions
from its suspend() and resume() interfaces.
Implement em28xx_ops: suspend/resume hooks. em28xx usb driver will
invoke em28xx_ops: suspend and resume hooks for all its extensions
from its suspend() and resume() interfaces.
[m.chehab@samsung.com: Fix a breakage caused by calling a non-existing
function call: schedule_delayed_work_sync(), and test if IR was defined
at suspend/resume]
Implement em28xx_ops: suspend/resume hooks. em28xx usb driver will
invoke em28xx_ops: suspend and resume hooks for all its extensions
from its suspend() and resume() interfaces.
Implement em28xx_ops: suspend/resume hooks. em28xx usb driver will
invoke em28xx_ops: suspend and resume hooks for all its extensions
from its suspend() and resume() interfaces.
Shuah Khan [Sat, 22 Feb 2014 00:50:13 +0000 (21:50 -0300)]
[media] em28xx: add suspend/resume to em28xx_ops
em28xx usb driver will have to suspend and resume its extensions. Adding
suspend and resume to em28xx_ops gives extensions the ability to install
suspend and resume that can be invoked from em28xx_usb driver suspend()
and resume() interfaces.
Approach:
Add power management support to em28xx usb driver. This driver works in
conjunction with extensions for each of the functions on the USB device
for video/audio/dvb/remote functionality that is present on media USB
devices it supports. During suspend and resume each of these extensions
will have to do their part in suspending the components they control.
Adding suspend and resume hooks to the existing struct em28xx_ops will
enable the extensions the ability to implement suspend and resume hooks
to be called from em28xx driver. The overall approach is as follows:
-- add suspend and resume hooks to em28xx_ops
-- add suspend and resume routines to em28xx-core to invoke suspend
and resume hooks for all registered extensions.
-- change em28xx dvb, audio, input, and video extensions to implement
em28xx_ops: suspend and resume hooks. These hooks do what is necessary
to suspend and resume the devices they control.
[media] au0828: rework GPIO management for HVR-950q
Restructure the way we bring the various GPIOs out of reset. In particular:
1. we only need to setup the GPIOs as outputs once
2. there's no point in writing 0x40 to register 0x00 since that's the EEPROM
write protect and already it's configured as an input
3. Separate out the act of enabling the power supply and bringing the tuner
and demod out of reset. If you don't then the chip may not be properly
enabled (as the power supply is still ramping up when the chip comes
out of reset). This can result in probing failures.
Hans de Goede [Sun, 23 Feb 2014 22:01:58 +0000 (19:01 -0300)]
[media] gspca_topro: Add a couple of missing length check in the packet parsing code
Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Dan Carpenter [Tue, 18 Feb 2014 15:00:45 +0000 (12:00 -0300)]
[media] gspca_stv06xx: remove an unneeded check
"err" is zero here so we don't need to check again.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Antonio Ospite [Mon, 30 Dec 2013 16:41:46 +0000 (13:41 -0300)]
[media] gspca_kinect: fix messages about kinect_read() return value
Messages relative to kinect_read() are printing "res" which contains the
return value of a previous kinect_write().
Print the correct value in the messages.
Cc: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Antonio Ospite <ospite@studenti.unina.it> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>