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: Ashay Jaiswal <ashayj@codeaurora.org>
This commit is contained in:
Ashay Jaiswal 2019-08-08 16:11:31 +05:30 committed by Gerrit - the friendly Code Review server
parent a3e55d9333
commit 0696f70e88
2 changed files with 79 additions and 3 deletions
drivers/power/supply/qcom
include/linux

View file

@ -166,7 +166,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];
@ -182,6 +182,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() -
@ -196,8 +228,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;
@ -208,6 +245,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);
@ -228,8 +268,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;
@ -244,6 +288,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);
@ -269,6 +316,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;
@ -282,6 +332,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);
@ -308,6 +361,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;
@ -321,6 +377,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);
@ -358,6 +417,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);
@ -463,6 +525,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;
@ -493,6 +558,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)
@ -510,6 +578,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;
@ -642,6 +713,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);

View file

@ -21,6 +21,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);