public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org
Cc: Linux-I2C <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: Question about i2c_xxx function on CONFIG_I2C
Date: Mon, 27 Jun 2011 13:30:56 +0200	[thread overview]
Message-ID: <20110627133056.1379854a@endymion.delvare> (raw)
In-Reply-To: <87aad3bvyf.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>

Hi Morimoto,

On Mon, 27 Jun 2011 16:00:08 +0900, kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org wrote:
> I'm using i2c_xxx function on some board.
> And sometimes I need very small kernel which doesn't need CONFIG_I2C.
> 
> But then (.config doesn't have CONFIG_I2C), the compile will fail.
> like this
> 
> error: implicit declaration of function 'i2c_get_adapter'
> error: implicit declaration of function 'i2c_transfer'
> 
> In this case, should I use #ifdef CONFIG_I2C in my code to solve this compile issue ?

Yes.

> Or is below #else in i2c.h good idea ?
> 
> --- i2c.h ---------
> #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
> ...
> extern struct i2c_adapter *i2c_get_adapter(int nr);
> ...
> #else
> ...
> #define i2c_get_adapter(nr) NULL
> ...
> #endif

I don't think this is a good idea in general. If the kernel lacks I2C
support, and your code uses it, then this is dead code, and you're much
better excluding that code completely from your build. Most likely
you'll be able to drop whole functions. I wouldn't count on the
compiler to optimize it all properly, and you said you want a very
small kernel.

Of course we could make better comments if we could see your actual
code. Maybe some ifdef magic in i2c.h would make sense for a few items,
as we already do for i2c_register_board_info for example.

-- 
Jean Delvare

  parent reply	other threads:[~2011-06-27 11:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-27  7:00 Question about i2c_xxx function on CONFIG_I2C kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ
     [not found] ` <87aad3bvyf.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
2011-06-27 11:30   ` Jean Delvare [this message]
     [not found]     ` <20110627133056.1379854a-R0o5gVi9kd7kN2dkZ6Wm7A@public.gmane.org>
2011-06-28  3:37       ` kuninori.morimoto.gx-Re5JQEeQqe8AvxtiuMwx3w
2011-06-27 14:04   ` Zhang, Shijie

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=20110627133056.1379854a@endymion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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