All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Pavel Machek <pavel@ucw.cz>
Cc: linux-kernel@vger.kernel.org, mochel@digitalimplant.org,
	benh@kernel.crashing.org, david-b@pacbell.net
Subject: Re: [patch] enums to clear suspend-state confusion
Date: Tue, 17 Aug 2004 15:27:42 -0700	[thread overview]
Message-ID: <20040817152742.17d3449d.akpm@osdl.org> (raw)
In-Reply-To: <20040817212510.GA744@elf.ucw.cz>

Pavel Machek <pavel@ucw.cz> wrote:
>
> Hi!
> 
> > This patch should clear up some confusion between driver model and
> > drivers people, and also prepares way to add runtime power managment
> > later. Please apply,
> 
> PCI states are now marked with PCI_D? so that confusion is not
> possible. Andrew complained about warning in to_pci_state(); I do not
> see it, but I added catch-all return anyway.
> 
> I'd like this to be applied, so I can start fixing the drivers...
> 

Sure, let's try to get this done.

> +static inline enum pci_state to_pci_state(suspend_state_t state)
> +{
> +	if (SUSPEND_EQ(state, PM_SUSPEND_ON))
> +		return PCI_D0;
> +	if (SUSPEND_EQ(state, PM_SUSPEND_STANDBY))
> +		return PCI_D1;
> +	if (SUSPEND_EQ(state, PM_SUSPEND_MEM))
> +		return PCI_D3hot;
> +	if (SUSPEND_EQ(state, PM_SUSPEND_DISK))
> +		return PCI_D3cold;
> +	BUG();
> +	return PCI_D0;	/* akpm complained about warnings? */
> +}
> +
> ...
> +/*
> + * For now, drivers only get system state. Later, this is going to become
> + * structure or something to enable runtime power managment.
> + */
> +typedef enum system_state suspend_state_t;
> +
> +#define SUSPEND_EQ(a, b) (a == b)
> +
>  enum {
>  	PM_DISK_FIRMWARE = 1,
>  	PM_DISK_PLATFORM,

This is a bit ugly, and I don't think it actually works.

If, at some time in the future you change the suspend state to a struct
then you will want to pass that thing around by reference, not by value. 
Hence your new suspend_state_t will need to be typecast to a pointer to
struct, and not a struct.  And that's not a thing which we do in-kernel
much at all.  (There's nothing wrong with the practice per-se, but in the
kernel it does violate the principle of least surprise).

So if you really do intend to add more things to the suspend state I'd
suggest that you set the final framework in place immediately.  Do:

struct suspend_state {
	enum system_state state;
}

static inline enum pci_state to_pci_state(struct suspend_state *state)
{
	if (state->state == PM_SUSPEND_ON)
		return PCI_D0;
	if (state->state == PM_SUSPEND_STANDBY)
		return PCI_D1;
	...
}

  reply	other threads:[~2004-08-17 22:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-12 12:02 [patch] enums to clear suspend-state confusion Pavel Machek
2004-08-16  0:59 ` Andrew Morton
2004-08-16  6:25   ` Pavel Machek
2004-08-16 14:09 ` Takashi Iwai
2004-08-16 20:11   ` Pavel Machek
2004-08-17 21:25 ` Pavel Machek
2004-08-17 22:27   ` Andrew Morton [this message]
2004-08-17 22:37     ` Pavel Machek
2004-08-17 23:12       ` Andrew Morton
2004-08-18  0:27         ` Pavel Machek
2004-08-18  2:04           ` Benjamin Herrenschmidt
2004-08-18  6:12             ` Pavel Machek
2004-08-18  6:55               ` Benjamin Herrenschmidt
2004-08-18 13:03                 ` Pavel Machek
2004-08-18 14:29                 ` Patrick Mochel
2004-08-18 15:17                 ` David Brownell
2004-08-18 20:47                   ` Pavel Machek
2004-08-18 17:31           ` Alan Cox
2004-08-18 18:28             ` David Brownell
2004-08-18 20:35             ` Pavel Machek
2004-08-18  6:26         ` Pavel Machek
2004-08-18  6:30           ` Andrew Morton
2004-08-18 10:22           ` Takashi Iwai
     [not found] <566B962EB122634D86E6EE29E83DD808182C3774@hdsmsx403.hd.intel.com>
2004-08-19  5:59 ` Len Brown
2004-08-19  8:19   ` Pavel Machek

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=20040817152742.17d3449d.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=benh@kernel.crashing.org \
    --cc=david-b@pacbell.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@digitalimplant.org \
    --cc=pavel@ucw.cz \
    /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.