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

Commit da020924 authored by Ashay Jaiswal's avatar Ashay Jaiswal Committed by Gerrit - the friendly Code Review server
Browse files

pmic-voter: add support to report override votes



Add support to report if a votable is voted via override
voting mechanism.
While at it, add valid pointer checks in global voter functions.

Change-Id: Ib867144c92f4ae99d9391190f75c8a6c95a3f4f0
Signed-off-by: default avatarAshay Jaiswal <ashayj@codeaurora.org>
parent e0498ad9
Loading
Loading
Loading
Loading
+77 −3
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ static int get_client_id(struct votable *votable, const char *client_str)

static char *get_client_str(struct votable *votable, int client_id)
{
	if (client_id == -EINVAL)
	if (!votable || (client_id == -EINVAL))
		return NULL;

	return votable->client_strs[client_id];
@@ -189,6 +189,38 @@ void unlock_votable(struct votable *votable)
	mutex_unlock(&votable->vote_lock);
}

/**
 * is_override_vote_enabled() -
 * is_override_vote_enabled_locked() -
 *		The unlocked and locked variants of getting whether override
		vote is enabled.
 * @votable:	the votable object
 *
 * Returns:
 *	True if the client's vote is enabled; false otherwise.
 */
bool is_override_vote_enabled_locked(struct votable *votable)
{
	if (!votable)
		return false;

	return votable->override_result != -EINVAL;
}

bool is_override_vote_enabled(struct votable *votable)
{
	bool enable;

	if (!votable)
		return false;

	lock_votable(votable);
	enable = is_override_vote_enabled_locked(votable);
	unlock_votable(votable);

	return enable;
}

/**
 * is_client_vote_enabled() -
 * is_client_vote_enabled_locked() -
@@ -203,8 +235,13 @@ void unlock_votable(struct votable *votable)
bool is_client_vote_enabled_locked(struct votable *votable,
							const char *client_str)
{
	int client_id = get_client_id(votable, client_str);

	int client_id;

	if (!votable || !client_str)
		return false;

	client_id = get_client_id(votable, client_str);
	if (client_id < 0)
		return false;

@@ -215,6 +252,9 @@ bool is_client_vote_enabled(struct votable *votable, const char *client_str)
{
	bool enabled;

	if (!votable || !client_str)
		return false;

	lock_votable(votable);
	enabled = is_client_vote_enabled_locked(votable, client_str);
	unlock_votable(votable);
@@ -235,8 +275,12 @@ bool is_client_vote_enabled(struct votable *votable, const char *client_str)
 */
int get_client_vote_locked(struct votable *votable, const char *client_str)
{
	int client_id = get_client_id(votable, client_str);
	int client_id;

	if (!votable || !client_str)
		return -EINVAL;

	client_id = get_client_id(votable, client_str);
	if (client_id < 0)
		return -EINVAL;

@@ -251,6 +295,9 @@ int get_client_vote(struct votable *votable, const char *client_str)
{
	int value;

	if (!votable || !client_str)
		return -EINVAL;

	lock_votable(votable);
	value = get_client_vote_locked(votable, client_str);
	unlock_votable(votable);
@@ -276,6 +323,9 @@ int get_client_vote(struct votable *votable, const char *client_str)
 */
int get_effective_result_locked(struct votable *votable)
{
	if (!votable)
		return -EINVAL;

	if (votable->force_active)
		return votable->force_val;

@@ -289,6 +339,9 @@ int get_effective_result(struct votable *votable)
{
	int value;

	if (!votable)
		return -EINVAL;

	lock_votable(votable);
	value = get_effective_result_locked(votable);
	unlock_votable(votable);
@@ -315,6 +368,9 @@ int get_effective_result(struct votable *votable)
 */
const char *get_effective_client_locked(struct votable *votable)
{
	if (!votable)
		return NULL;

	if (votable->force_active)
		return DEBUG_FORCE_CLIENT;

@@ -328,6 +384,9 @@ const char *get_effective_client(struct votable *votable)
{
	const char *client_str;

	if (!votable)
		return NULL;

	lock_votable(votable);
	client_str = get_effective_client_locked(votable);
	unlock_votable(votable);
@@ -365,6 +424,9 @@ int vote(struct votable *votable, const char *client_str, bool enabled, int val)
	int rc = 0;
	bool similar_vote = false;

	if (!votable || !client_str)
		return -EINVAL;

	lock_votable(votable);

	client_id = get_client_id(votable, client_str);
@@ -470,6 +532,9 @@ int vote_override(struct votable *votable, const char *override_client,
{
	int rc = 0;

	if (!votable || !override_client)
		return -EINVAL;

	lock_votable(votable);
	if (votable->force_active) {
		votable->override_result = enabled ? val : -EINVAL;
@@ -500,6 +565,9 @@ int rerun_election(struct votable *votable)
	int rc = 0;
	int effective_result;

	if (!votable)
		return -EINVAL;

	lock_votable(votable);
	effective_result = get_effective_result_locked(votable);
	if (votable->callback)
@@ -517,6 +585,9 @@ struct votable *find_votable(const char *name)
	struct votable *v;
	bool found = false;

	if (!name)
		return NULL;

	spin_lock_irqsave(&votable_list_slock, flags);
	if (list_empty(&votable_list))
		goto out;
@@ -649,6 +720,9 @@ struct votable *create_votable(const char *name,
	struct votable *votable;
	unsigned long flags;

	if (!name)
		return ERR_PTR(-EINVAL);

	votable = find_votable(name);
	if (votable)
		return ERR_PTR(-EEXIST);
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ enum votable_type {
bool is_client_vote_enabled(struct votable *votable, const char *client_str);
bool is_client_vote_enabled_locked(struct votable *votable,
							const char *client_str);
bool is_override_vote_enabled(struct votable *votable);
bool is_override_vote_enabled_locked(struct votable *votable);
int get_client_vote(struct votable *votable, const char *client_str);
int get_client_vote_locked(struct votable *votable, const char *client_str);
int get_effective_result(struct votable *votable);