All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Himanshu Jha <himanshujha199640@gmail.com>
Cc: Afonso Bordado <afonsobordado@az8.co>,
	knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v4 4/5] iio: fxas21002c: add ODR/Scale support
Date: Sun, 16 Sep 2018 12:50:51 +0100	[thread overview]
Message-ID: <20180916125051.1a904196@archlinux> (raw)
In-Reply-To: <20180914173058.GA8405@himanshu-Vostro-3559>

On Fri, 14 Sep 2018 23:00:58 +0530
Himanshu Jha <himanshujha199640@gmail.com> wrote:

> On Fri, Sep 14, 2018 at 04:26:44PM +0100, Afonso Bordado wrote:
> > Hi,
> > 
> > Thanks for your help with this.
> >   
> > > And I suspect it may be originating from your code snippet:
> > > 
> > > #define FXAS21002C_SCALE(scale) (IIO_DEGREE_TO_RAD(62500U >>
> > > (scale)))
> > > 
> > > and looking at the implementation:
> > > 
> > > include/linux/iio/iio.h
> > > /**
> > >  * IIO_DEGREE_TO_RAD() - Convert degree to rad
> > >  * @deg: A value in degree
> > >  *
> > >  * Returns the given value converted from degree to rad
> > >  */
> > > #define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) /
> > > 18000000ULL)
> > > 
> > > This '/' operator might be the culprit!
> > > 
> > > Just for checking that the error, remove the macro declaration
> > > `FXAS21002C_SCALE`
> > > plus its usage and re-cross compile using `make ARCH=i386`.
> > > 
> > > In my case I used the `div64_s64` function handles builds for both
> > > 32/64
> > > arch accordingly.  
> > 
> > Yes, this is indeed the culprit. If `div64_s64` works the same way, I
> > wonder if the best option is to change the macro definition.  
> 
> "....works the same way" ?
> 
> Let us assume that the problem arises due to the 64 bit division, in
> which gcc places the __divdi3() runtime function to promote the
> "freestanding" environment implementation. And then linking fails
> due to unavailability of definitions/declarations of the aforementioned
> function.
> 
> With `div64_s64` usgae the linker binds the definition present at lib/div64.c
> and the build completes successfully whether building for 32/64 bit
> environment.
> 
> But then why didn't this error showed up in the past, in the rest 
> of the drivers ?
> 
> I see its wide usage in IIO without bug reports:
> 
> himanshu@himanshu-Vostro-3559:~/linux-next$ git grep -w "IIO_DEGREE_TO_RAD" drivers/iio/ | wc -l
> 34
> 
> And that concludes, that there is some problem within your code!
> 
> In the meantime, you can try to look the disassembly of the function
> where this macro is actually used and search for __divdi3/__udivdi3
> function referenced in the plt.
> 
> I might be wrong though...
> 
> Wait a while for the experts to join in!
> 
The reason it's not usually a problem is because it is a compile time
constant for all the other drivers and GCC is more than happy to do
it on 32 bit platforms.

Now whilst it looks like you are doing something that needs to be dynamic
there are actually only a few possible values so this is something we
'want' to do at compile time rather than runtime.  Just add a look up
table for those 4 values instead of computing the conversion every
time.

Thanks,

Jonathan


  reply	other threads:[~2018-09-16 11:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11 15:00 [PATCH v4 1/5] iio: gyro: add support for fxas21002c Afonso Bordado
2018-09-11 15:00 ` [PATCH v4 2/5] iio: gyro: add device tree " Afonso Bordado
2018-09-11 15:00 ` [PATCH v4 3/5] dt-bindings: fxas21002c: Document the fxas21002c I2C bindings Afonso Bordado
2018-09-16 12:59   ` Jonathan Cameron
2018-09-16 13:01   ` Jonathan Cameron
2018-09-11 15:00 ` [PATCH v4 4/5] iio: fxas21002c: add ODR/Scale support Afonso Bordado
2018-09-12  9:26   ` kbuild test robot
2018-09-12 18:23     ` Himanshu Jha
2018-09-14 15:26       ` Afonso Bordado
2018-09-14 17:30         ` Himanshu Jha
2018-09-16 11:50           ` Jonathan Cameron [this message]
2018-09-11 15:00 ` [PATCH v4 5/5] MAINTAINERS: add entry for fxas21002c gyro driver Afonso Bordado
2018-09-11 16:17 ` [PATCH v4 1/5] iio: gyro: add support for fxas21002c Song Qiang
2018-09-16 11:57 ` Jonathan Cameron

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=20180916125051.1a904196@archlinux \
    --to=jic23@kernel.org \
    --cc=afonsobordado@az8.co \
    --cc=devicetree@vger.kernel.org \
    --cc=himanshujha199640@gmail.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.