linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roy Im <roy.im.opensource@diasemi.com>
To: Jes Sorensen <jes.sorensen@gmail.com>,
	Roy Im <roy.im.opensource@diasemi.com>,
	Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Brian Masney <masneyb@onstation.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Greg KH <gregkh@linuxfoundation.org>,
	Lee Jones <lee.jones@linaro.org>, Luca Weiss <luca@z3ntu.xyz>,
	Maximilian Luz <luzmaximilian@gmail.com>,
	Pascal PAILLET-LME <p.paillet@st.com>,
	Rob Herring <robh@kernel.org>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Support Opensource <Support.Opensource@diasemi.com>,
	"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>
Subject: RE: [PATCH v16 3/3] Input: new da7280 haptic driver
Date: Thu, 23 Jul 2020 02:23:29 +0000	[thread overview]
Message-ID: <DB8PR10MB34362941F9428B498ED4B94E85760@DB8PR10MB3436.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <bdc76da9-9223-b6d9-1fc1-2ef6e3b7afa7@gmail.com>

On Thursday, July 23, 2020 12:24 AM, Jes Sorensen wrote:
> On 7/9/20 3:27 AM, Roy Im wrote:
> > Adds support for the Dialog DA7280 LRA/ERM Haptic Driver with multiple
> > mode and integrated waveform memory and wideband support.
> > It communicates via an I2C bus to the device.
> >
> > Signed-off-by: Roy Im <roy.im.opensource@diasemi.com>
> > ---
> > v16:
> > 	- Corrected some code and updated description in Kconfig.
> > v15:
> > 	- Removed some defines and updated some comments.
> > v14:
> > 	- Updated pwm related code, alignments and comments.
> > v13:
> > 	- Updated some conditions in pwm function and alignments.
> > v12: No changes.
> > v11:
> > 	- Updated the pwm related code, comments and typo.
> > v10:
> > 	- Updated the pwm related function and added some comments.
> > v9:
> > 	- Removed the header file and put the definitions into the c file.
> > 	- Updated the pwm code and error logs with %pE
> > v8:
> > 	- Added changes to support FF_PERIODIC/FF_CUSTOM and FF_CONSTANT.
> > 	- Updated the dt-related code.
> > 	- Removed memless related functions.
> > v7:
> > 	- Added more attributes to handle one value per file.
> > 	- Replaced and updated the dt-related code and functions called.
> > 	- Fixed error/functions.
> > v6: No changes.
> > v5: Fixed errors in Kconfig file.
> > v4: Updated code as dt-bindings are changed.
> > v3: No changes.
> > v2: Fixed kbuild error/warning
> >
> >
> >  drivers/input/misc/Kconfig  |   13 +
> >  drivers/input/misc/Makefile |    1 +
> >  drivers/input/misc/da7280.c | 1840
> > +++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 1854 insertions(+)
> >  create mode 100644 drivers/input/misc/da7280.c
> 
> Hi Roy,
> 
> Overall the driver looks pretty good now. I did find one issue, see below. If you fix that I am happy to add a Reviewed-by line.
> 
> Reviewed-By: Jes Sorensen <Jes.Sorensen@gmail.com>

Thanks a lot and I will fix as you advised below, then I will add a Reviewed-line in the next patch.

> 
> > diff --git a/drivers/input/misc/da7280.c b/drivers/input/misc/da7280.c
> > new file mode 100644 index 0000000..c8c42ac
> > --- /dev/null
> > +++ b/drivers/input/misc/da7280.c
> 
> [snip]
> 
> > +static int da7280_haptic_set_pwm(struct da7280_haptic *haptics, bool enabled)
> > +{
> > +	struct pwm_state state;
> > +	u64 period_mag_multi;
> > +	int error;
> > +
> > +	if (!haptics->gain && enabled) {
> > +		dev_err(haptics->dev,
> > +			"Please set the gain first for the pwm mode\n");
> > +		return -EINVAL;
> > +	}
> > +
> > +	pwm_get_state(haptics->pwm_dev, &state);
> > +	state.enabled = enabled;
> > +	if (enabled) {
> > +		period_mag_multi = state.period * haptics->gain;
> 
> You are multiplying an unsigned int to a u16 and storing it in a u64.
> However, C doesn't promote the types, so you'll end up with an
> unexpected result here. You can fix it by promoting state.period to u64, ie:
> 
> 		period_mage_multi = (u64)state.period * haptics->gain;
> 
> See the following example code which demonstrates the problem.
> 
> #include <stdio.h>
> #include <stdint.h>
> 
> uint64_t foo(unsigned int a, uint16_t b)
> {
> 	uint64_t tmp = a * b;
> 	return tmp;
> }
> 
> uint64_t bar(unsigned int a, uint16_t b)
> {
> 	uint64_t tmp = (uint64_t)a * b;
> 	return tmp;
> }
> 
> int main()
> {
> 	uint64_t val;
> 	unsigned int a = 0xff00ff00;
> 	uint16_t b = 0x200;
> 
> 	val = foo(a, b);
> 	printf("result(%0x, %0x) = %0llx\n", a, b, val);
> 
> 	val = bar(a, b);
> 	printf("result(%0x, %0x) = %0llx\n", a, b, val);
> }
> 
> Cheers,
> Jes

Yes, you are right, I see the different result, I will fix this.

Kind regards,
Roy


      reply	other threads:[~2020-07-23  2:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-09  7:27 [PATCH v16 0/3] da7280: haptic driver submission Roy Im
2020-07-09  7:27 ` [PATCH v16 1/3] MAINTAINERS: da7280 updates to the Dialog Semiconductor search terms Roy Im
2020-07-09  7:27 ` [PATCH v16 2/3] dt-bindings: input: Add document bindings for DA7280 Roy Im
2020-07-09  7:27 ` [PATCH v16 3/3] Input: new da7280 haptic driver Roy Im
2020-07-22 15:23   ` Jes Sorensen
2020-07-23  2:23     ` Roy Im [this message]

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=DB8PR10MB34362941F9428B498ED4B94E85760@DB8PR10MB3436.EURPRD10.PROD.OUTLOOK.COM \
    --to=roy.im.opensource@diasemi.com \
    --cc=Support.Opensource@diasemi.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jes.sorensen@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=luca@z3ntu.xyz \
    --cc=luzmaximilian@gmail.com \
    --cc=masneyb@onstation.org \
    --cc=p.paillet@st.com \
    --cc=robh@kernel.org \
    --cc=sameo@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).