diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2012-09-11 06:11:24 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-10-06 08:24:39 -0400 |
commit | 48cafec9a941c2dfe94d76642662bc20bf87fe08 (patch) | |
tree | 135943901bfccdb6a8e260fed60c6583fcc8021b | |
parent | a52eb6c02fa27efb5f8980312785fce1f77377e2 (diff) |
[media] rc: divide by zero bugs in s_tx_carrier()
"carrier" comes from a get_user() in ir_lirc_ioctl(). We need to test
that it's not zero before using it as a divisor. It might have been
nice to test for this ir_lirc_ioctl() but the mceusb driver uses zero to
disable carrier modulation.
The bug in redrat3 is a little more subtle. The ->carrier is passed to
mod_freq_to_val() which uses it as a divisor.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/rc/ene_ir.c | 5 | ||||
-rw-r--r-- | drivers/media/rc/nuvoton-cir.c | 3 | ||||
-rw-r--r-- | drivers/media/rc/redrat3.c | 3 |
3 files changed, 10 insertions, 1 deletions
diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c index 647dd951b0e8..d05ac15b5de4 100644 --- a/drivers/media/rc/ene_ir.c +++ b/drivers/media/rc/ene_ir.c | |||
@@ -881,10 +881,13 @@ static int ene_set_tx_mask(struct rc_dev *rdev, u32 tx_mask) | |||
881 | static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier) | 881 | static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier) |
882 | { | 882 | { |
883 | struct ene_device *dev = rdev->priv; | 883 | struct ene_device *dev = rdev->priv; |
884 | u32 period = 2000000 / carrier; | 884 | u32 period; |
885 | 885 | ||
886 | dbg("TX: attempt to set tx carrier to %d kHz", carrier); | 886 | dbg("TX: attempt to set tx carrier to %d kHz", carrier); |
887 | if (carrier == 0) | ||
888 | return -EINVAL; | ||
887 | 889 | ||
890 | period = 2000000 / carrier; | ||
888 | if (period && (period > ENE_CIRMOD_PRD_MAX || | 891 | if (period && (period > ENE_CIRMOD_PRD_MAX || |
889 | period < ENE_CIRMOD_PRD_MIN)) { | 892 | period < ENE_CIRMOD_PRD_MIN)) { |
890 | 893 | ||
diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c index 699eef39128b..2ea913a44ae8 100644 --- a/drivers/media/rc/nuvoton-cir.c +++ b/drivers/media/rc/nuvoton-cir.c | |||
@@ -517,6 +517,9 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier) | |||
517 | struct nvt_dev *nvt = dev->priv; | 517 | struct nvt_dev *nvt = dev->priv; |
518 | u16 val; | 518 | u16 val; |
519 | 519 | ||
520 | if (carrier == 0) | ||
521 | return -EINVAL; | ||
522 | |||
520 | nvt_cir_reg_write(nvt, 1, CIR_CP); | 523 | nvt_cir_reg_write(nvt, 1, CIR_CP); |
521 | val = 3000000 / (carrier) - 1; | 524 | val = 3000000 / (carrier) - 1; |
522 | nvt_cir_reg_write(nvt, val & 0xff, CIR_CC); | 525 | nvt_cir_reg_write(nvt, val & 0xff, CIR_CC); |
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c index 49731b1a9c57..9f5a17bb5ef5 100644 --- a/drivers/media/rc/redrat3.c +++ b/drivers/media/rc/redrat3.c | |||
@@ -890,6 +890,9 @@ static int redrat3_set_tx_carrier(struct rc_dev *rcdev, u32 carrier) | |||
890 | struct device *dev = rr3->dev; | 890 | struct device *dev = rr3->dev; |
891 | 891 | ||
892 | rr3_dbg(dev, "Setting modulation frequency to %u", carrier); | 892 | rr3_dbg(dev, "Setting modulation frequency to %u", carrier); |
893 | if (carrier == 0) | ||
894 | return -EINVAL; | ||
895 | |||
893 | rr3->carrier = carrier; | 896 | rr3->carrier = carrier; |
894 | 897 | ||
895 | return carrier; | 898 | return carrier; |