Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48cafec9 authored by Dan Carpenter's avatar Dan Carpenter Committed by Mauro Carvalho Chehab
Browse files

[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: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent a52eb6c0
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -881,10 +881,13 @@ static int ene_set_tx_mask(struct rc_dev *rdev, u32 tx_mask)
static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier)
static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier)
{
{
	struct ene_device *dev = rdev->priv;
	struct ene_device *dev = rdev->priv;
	u32 period = 2000000 / carrier;
	u32 period;


	dbg("TX: attempt to set tx carrier to %d kHz", carrier);
	dbg("TX: attempt to set tx carrier to %d kHz", carrier);
	if (carrier == 0)
		return -EINVAL;


	period = 2000000 / carrier;
	if (period && (period > ENE_CIRMOD_PRD_MAX ||
	if (period && (period > ENE_CIRMOD_PRD_MAX ||
			period < ENE_CIRMOD_PRD_MIN)) {
			period < ENE_CIRMOD_PRD_MIN)) {


+3 −0
Original line number Original line Diff line number Diff line
@@ -517,6 +517,9 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
	struct nvt_dev *nvt = dev->priv;
	struct nvt_dev *nvt = dev->priv;
	u16 val;
	u16 val;


	if (carrier == 0)
		return -EINVAL;

	nvt_cir_reg_write(nvt, 1, CIR_CP);
	nvt_cir_reg_write(nvt, 1, CIR_CP);
	val = 3000000 / (carrier) - 1;
	val = 3000000 / (carrier) - 1;
	nvt_cir_reg_write(nvt, val & 0xff, CIR_CC);
	nvt_cir_reg_write(nvt, val & 0xff, CIR_CC);
+3 −0
Original line number Original line Diff line number Diff line
@@ -890,6 +890,9 @@ static int redrat3_set_tx_carrier(struct rc_dev *rcdev, u32 carrier)
	struct device *dev = rr3->dev;
	struct device *dev = rr3->dev;


	rr3_dbg(dev, "Setting modulation frequency to %u", carrier);
	rr3_dbg(dev, "Setting modulation frequency to %u", carrier);
	if (carrier == 0)
		return -EINVAL;

	rr3->carrier = carrier;
	rr3->carrier = carrier;


	return carrier;
	return carrier;