alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: "Jörg Krause" <joerg.krause@embedded.rocks>
To: Clemens Ladisch <clemens@ladisch.de>, alsa-devel@alsa-project.org
Subject: Re: [PATCH] pcm: softvol: fix signedness of tlv data type
Date: Sun, 08 May 2016 20:18:19 +0200	[thread overview]
Message-ID: <1462731499.2641.3.camel@embedded.rocks> (raw)
In-Reply-To: <38c794bd-5eda-2bb2-7022-a13e2869dc3a@ladisch.de>

Hello,

On Sa, 2016-05-07 at 09:06 +0200, Clemens Ladisch wrote:
> Jörg Krause wrote:
> > For the softvol plugin the TLV data are written wrong, e.g. for the
> > default values
> > of min_dB = -51 dB and max_dB = 0 dB, alsactl generates the
> > following state:
> > 
> >                         tlv '00000001000000080000000000000014'
> > 
> > As both min_dB and max_dB can be negative numbers, the tlv type
> > must not be
> > unsigned.
> 
> TLVs always are unsigned.  But they can contain bit patterns that are
> to
> be interpreted as signed.

I see!

> > -	unsigned int tlv[4];
> > +	int tlv[4];
> >  	tlv[0] = SND_CTL_TLVT_DB_SCALE;
> >  	tlv[1] = 2 * sizeof(int);
> >  	tlv[2] = svol->min_dB * 100;
> 
> The problem is that conversion of a negative floating-point number
> into
> an unsigned integer results in undefined behaviour, and on your
> architecture (whatever it is), this results in zero.
> 
> The correct way to handle this would be something like this:
> 
>   tlv[i] = (int)(...);

This fixes the issue for my ARM target, many thanks! I'll send an
updated version.

Many thanks for the review!

Best regards,
Jörg Krause
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

      reply	other threads:[~2016-05-08 18:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 21:08 [PATCH] pcm: softvol: fix signedness of tlv data type Jörg Krause
2016-05-07  7:06 ` Clemens Ladisch
2016-05-08 18:18   ` Jörg Krause [this message]

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=1462731499.2641.3.camel@embedded.rocks \
    --to=joerg.krause@embedded.rocks \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).