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

Commit e4ebe5fe authored by Lee Jones's avatar Lee Jones Committed by Greg Kroah-Hartman
Browse files

misc: st_core: Protect unsigned value against becoming negative



Coverity reported:
  This less-than-zero comparison of an unsigned value is never true.

In answer to that, we only ever decrement if protos_registered is
positive.  We can subsequently remove the paranoid checking during
unregister.

Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0ae39cc9
Loading
Loading
Loading
Loading
+5 −6
Original line number Original line Diff line number Diff line
@@ -153,8 +153,9 @@ static void st_reg_complete(struct st_data_s *st_gdata, char err)
				(st_gdata->list[i]->priv_data, err);
				(st_gdata->list[i]->priv_data, err);
			pr_info("protocol %d's cb sent %d\n", i, err);
			pr_info("protocol %d's cb sent %d\n", i, err);
			if (err) { /* cleanup registered protocol */
			if (err) { /* cleanup registered protocol */
				st_gdata->protos_registered--;
				st_gdata->is_registered[i] = false;
				st_gdata->is_registered[i] = false;
				if (st_gdata->protos_registered)
					st_gdata->protos_registered--;
			}
			}
		}
		}
	}
	}
@@ -639,14 +640,12 @@ long st_unregister(struct st_proto_s *proto)
		return -EPROTONOSUPPORT;
		return -EPROTONOSUPPORT;
	}
	}


	if (st_gdata->protos_registered)
		st_gdata->protos_registered--;
		st_gdata->protos_registered--;

	remove_channel_from_table(st_gdata, proto);
	remove_channel_from_table(st_gdata, proto);
	spin_unlock_irqrestore(&st_gdata->lock, flags);
	spin_unlock_irqrestore(&st_gdata->lock, flags);


	/* paranoid check */
	if (st_gdata->protos_registered < ST_EMPTY)
		st_gdata->protos_registered = ST_EMPTY;

	if ((st_gdata->protos_registered == ST_EMPTY) &&
	if ((st_gdata->protos_registered == ST_EMPTY) &&
	    (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
	    (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
		pr_info(" all chnl_ids unregistered ");
		pr_info(" all chnl_ids unregistered ");