All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Courtier-Dutton <James@superbug.co.uk>
To: Takashi Iwai <tiwai@suse.de>
Cc: ALSA development <alsa-devel@alsa-project.org>,
	Jaroslav Kysela <perex@suse.cz>
Subject: Re: dB gain
Date: Wed, 31 May 2006 12:04:39 +0100	[thread overview]
Message-ID: <447D7847.50406@superbug.co.uk> (raw)
In-Reply-To: <s5hlksieajf.wl%tiwai@suse.de>

Takashi Iwai wrote:
> No, please not yet.  The code is still not good enough for commit.
>
> For example, some things to be fixed regarding the code (and coding
> style) are below:
>
> +static int uint32_to_message(struct snd_ctl_misc *misc, u32 value)
> +{
> +	unsigned int pointer = misc->length;
> +	u32 *store = (u32*) &misc->message[pointer];
>
> This cast isn't always allowed.
>
> +	*store = value;
> +	misc->length += sizeof(u32);
> +	return 0;
> +}
>
>   
What do I use instead?

+	misc->message[pointer++] = value & 0xff;
+	misc->message[pointer++] = (value >> 8) & 0xff;
+	misc->message[pointer++] = (value >> 16) & 0xff;
+	misc->message[pointer++] = (value >> 24) & 0xff;


> +static int add_message_tlv_to_container(
> +	struct snd_ctl_misc *misc, unsigned int length, unsigned char *message)
>
> Unconventional indentation.
>
> +	unsigned int pointer = misc->length;
> +	unsigned int n;
> +	for(n=0; n<length; n++) {
> +		misc->message[pointer++] = message[n];
> +	}
>
> What's wrong with memcpy()?
>   
Nothing wrong with memcpy().
> +static int snd_ctl_misc_user(struct snd_ctl_file *ctl,
> +				  struct snd_ctl_misc __user *_misc)
> +{
> +	struct snd_ctl_misc *misc;
> +	struct snd_card *card = ctl->card;
> +	struct snd_kcontrol *kctl;
> +	struct snd_ctl_elem_info2 info2;
> +	int result=0;
> +	int numid;
> +	unsigned int received_length;
> +	unsigned int tlv_type;
> +	unsigned int tlv_length;
> +	unsigned int tlv_value;
> +	unsigned int container_type;
> +	unsigned int container_length;
> +	
> +	misc = kmalloc(2048, GFP_KERNEL);
> +	if (misc == NULL)
> +		return -ENOMEM;
>
> Why always 2048?
>   
No particular reason, just seemed like a ball park value that I should 
not have to change any time soon. I could probably replace it with some 
getuser32 calls to get the required length from the userspace app. Is 
getuser32() the correct call to use instead of copy_from_user(), if all 
one needs is a 4 byte integer from a particular memory location?
> Also, cases should be aligned to switch().
>   
Ok.
> But, above all, such a large switch() is ugly.  Better to put the
> container-type specific handling out of this function.
>
> Although this whole block basically belongs only to DB_SCALE case, the
> current code looks as if this block is commonly handled regardless of
> the container type.
>   
That's true. I will look at putting the case action as a separate function.

> +struct snd_ctl_misc {
> +	u32 version;
> +	u32 length;
> +	unsigned char message[];
> +};
>
> The empty array isn't portable.
>   
Ok, how do I do this then?
The array is not actually empty, but it's size is dependent on the 
length field.

> +typedef int (snd_kcontrol_info2_t) (struct snd_kcontrol * kcontrol, int type, struct snd_ctl_elem_info2 * uinfo);
>
> The type should be non-numeric but constants (bitwise define or
> enum).
>   
I don't understand. This is almost an exact copy of:
typedef int (snd_kcontrol_info_t) (struct snd_kcontrol * kcontrol, 
struct snd_ctl_elem_info * uinfo);
That is already in the code.

  reply	other threads:[~2006-05-31 11:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-27 19:03 dB gain James Courtier-Dutton
2006-05-29 13:08 ` Takashi Iwai
2006-05-29 13:47   ` Jaroslav Kysela
2006-05-29 14:17     ` Jaroslav Kysela
2006-05-29 14:28       ` Takashi Iwai
2006-05-29 14:55         ` Jaroslav Kysela
2006-05-29 15:12           ` James Courtier-Dutton
2006-05-29 15:41             ` Takashi Iwai
2006-05-29 18:34               ` Jaroslav Kysela
2006-05-29 19:21                 ` James Courtier-Dutton
2006-05-29 14:50   ` James Courtier-Dutton
2006-05-29 15:54     ` Takashi Iwai
2006-05-29 17:34       ` James Courtier-Dutton
2006-05-29 18:11         ` Takashi Iwai
2006-05-29 18:27           ` Jaroslav Kysela
2006-05-30 18:59             ` James Courtier-Dutton
2006-05-30 19:49               ` Jaroslav Kysela
2006-05-31 10:47               ` Takashi Iwai
2006-05-31 11:04                 ` James Courtier-Dutton [this message]
2006-05-31 11:31                   ` Takashi Iwai
2006-05-31 11:18             ` 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=447D7847.50406@superbug.co.uk \
    --to=james@superbug.co.uk \
    --cc=alsa-devel@alsa-project.org \
    --cc=perex@suse.cz \
    --cc=tiwai@suse.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 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.