All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC
Date: Fri, 03 May 2019 10:05:25 +0200	[thread overview]
Message-ID: <s5htvecrmii.wl-tiwai@suse.de> (raw)
In-Reply-To: <20190503064729.GF14916@sirena.org.uk>

On Fri, 03 May 2019 08:47:29 +0200,
Mark Brown wrote:
> 
> > > > +#define cx2072x_plbk_eq_en_info		snd_ctl_boolean_mono_info
> 
> > > Why not just use the function directly rather than hiding it?
> 
> > Just a standard idiom.  Can be replaced if preferred.
> 
> Please.

BTW, a good reason for the style above is that it makes code more
undrestandable.  For defining a ctl element, typically we define three
callback functions, info, get and put, in that order:

static int foo_info()
{
	....
}

static int foo_get()
{
	....
}

static int foo_put()
{
	...
};

and often the actual snd_kcontrol_new table containing these callbacks
appears much later, where you'd need to scroll down a few screens to
read that point.

In the above, especially defining the info callback at the beginning
is important.  By reading foo_init() at first, readers can know which
type (int, boolean, enum, etc) and the number of elements to be used
in get/put callbacks beforehand.  It's a commonly seen mistake, for
example, that a wrong type (e.g. integer) is passed to info callback
while enum type is used in the get/put.

The #define above keeps this foo_info() definition while optimizing
with the standard helper.  If we drop this and set
snd_ctl_boolean_mono_info directly in the snd_kcontrol_new entry,
you'll have to go and back the screen just to take a look at the info
callback.

That's why I called it a standard idiom.  It's not strictly necessary,
but often help reading / reviewing the code.  Though, it's just
another bikeshed theme, so I'm not sticking with this style.


thanks,

Takashi

  parent reply	other threads:[~2019-05-03  8:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-23 14:13 [PATCH 0/2] ASoC: CX2072X codec support (revised) Takashi Iwai
2019-04-23 14:13 ` [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC Takashi Iwai
2019-04-27 17:59   ` Mark Brown
2019-05-02  7:04     ` Takashi Iwai
2019-05-02  7:52       ` Takashi Iwai
2019-05-03  6:52         ` Mark Brown
     [not found]       ` <20190503064729.GF14916@sirena.org.uk>
2019-05-03  7:18         ` Takashi Iwai
     [not found]           ` <20190506042625.GK14916@sirena.org.uk>
2019-05-06  9:55             ` Takashi Iwai
2019-05-06 14:05               ` Mark Brown
2019-05-06 15:26                 ` Takashi Iwai
2019-05-08  8:10                   ` Mark Brown
2019-05-08  8:16                     ` Takashi Iwai
2019-05-08  8:59                       ` Mark Brown
2019-05-08  9:16                         ` Takashi Iwai
2019-05-08 10:10                           ` Mark Brown
2019-05-03  8:05         ` Takashi Iwai [this message]
2019-04-23 14:13 ` [PATCH 2/2] ASoC: Intel: Add machine driver for CX2072X on BYT/CHT platforms Takashi Iwai
2019-04-23 19:20   ` Pierre-Louis Bossart
2019-04-23 19:39     ` Takashi Iwai
2019-04-24 13:08       ` Takashi Iwai

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=s5htvecrmii.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=pierre-louis.bossart@linux.intel.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 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.