From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: linux-pwm@vger.kernel.org, kernel@pengutronix.de
Subject: [PATCH 1/4] pwm: don't use memcmp to compare struct state variables
Date: Mon, 7 Jan 2019 20:49:37 +0100 [thread overview]
Message-ID: <20190107194938.3004-2-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20190107194938.3004-1-u.kleine-koenig@pengutronix.de>
Given that struct pwm_state is sparse (at least on some platforms)
variables of this type might represent the same state because all fields
are pairwise identical but still memcmp returns a difference because some
of the unused bits are different.
To prevent surprises compare member by member instead of the whole occupied
memory.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/pwm/core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 1581f6ab1b1f..253a459fe0d8 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -472,7 +472,10 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state)
state->duty_cycle > state->period)
return -EINVAL;
- if (!memcmp(state, &pwm->state, sizeof(*state)))
+ if (state->period == pwm->state.period &&
+ state->duty_cycle == pwm->state.duty_cycle &&
+ state->polarity == pwm->state.polarity &&
+ state->enabled == pwm->state.enabled)
return 0;
if (pwm->chip->ops->apply) {
--
2.20.1
next prev parent reply other threads:[~2019-01-07 19:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-07 19:49 [PATCH 0/4] pwm patches for the next merge window Uwe Kleine-König
2019-01-07 19:49 ` Uwe Kleine-König [this message]
2019-01-07 19:49 ` [PATCH 2/4] pwm: drop per-chip dbg_show callback Uwe Kleine-König
2019-01-10 8:36 ` Thierry Reding
2019-01-10 8:52 ` Uwe Kleine-König
2019-01-07 19:49 ` [PATCH 3/4] pwm: rearrange structures to group members by purpose Uwe Kleine-König
2019-01-07 19:49 ` [PATCH 4/4] [RFC] Documentation: pwm: rework documentation for the framework Uwe Kleine-König
2019-07-26 9:39 ` Uwe Kleine-König
2019-09-24 12:00 ` Uwe Kleine-König
2019-01-10 8:35 ` [PATCH 0/4] pwm patches for the next merge window Thierry Reding
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190107194938.3004-2-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=kernel@pengutronix.de \
--cc=linux-pwm@vger.kernel.org \
--cc=thierry.reding@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).