Description / Steps to reproduce the issue
Some lower-half implementations of the I2S driver do not follow the correct return contract.
For instance, i2s_txsamplerate requires the return value to be the current bitrate. However, some drivers (i.e. rp2040_i2s.c) return 0 on success and a negated errno value on failure. This is not correct, it should be the bitrate on success.
|
/**************************************************************************** |
|
* Name: rp2040_i2s_txsamplerate |
|
* |
|
* Description: |
|
* Set the I2S TX sample rate. |
|
* |
|
* Input Parameters: |
|
* dev - Device-specific state data |
|
* rate - The I2S sample rate in samples (not bits) per second |
|
* |
|
* Returned Value: |
|
* OK on success; a negated errno value on failure. |
|
* |
|
****************************************************************************/ |
|
|
|
static uint32_t rp2040_i2s_txsamplerate(struct i2s_dev_s *dev, uint32_t rate) |
|
{ |
|
struct rp2040_i2s_s *priv = (struct rp2040_i2s_s *)dev; |
|
|
|
DEBUGASSERT(priv && priv->samplerate >= 0 && rate > 0); |
|
|
|
if (rate < 8000) |
|
{ |
|
return -EINVAL; |
|
} |
|
|
|
priv->samplerate = rate; |
|
return 0; |
|
} |
|
|
|
/**************************************************************************** |
|
* Name: I2S_TXSAMPLERATE |
|
* |
|
* Description: |
|
* Set the I2S TX sample rate. NOTE: This will have no effect if (1) the |
|
* driver does not support an I2S transmitter or if (2) the sample rate is |
|
* driven by the I2S frame clock. This may also have unexpected side- |
|
* effects of the TX sample is coupled with the RX sample rate. |
|
* |
|
* Input Parameters: |
|
* dev - Device-specific state data |
|
* rate - The I2S sample rate in samples (not bits) per second |
|
* |
|
* Returned Value: |
|
* Returns the resulting bitrate |
|
* |
|
****************************************************************************/ |
|
|
|
#define I2S_TXSAMPLERATE(d,r) \ |
|
((d)->ops->i2s_txsamplerate ? (d)->ops->i2s_txsamplerate(d,r) : -ENOTTY) |
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
Arch Linux
NuttX Version
master
Issue Architecture
[Arch: all]
Issue Area
[Area: Drivers]
Host information
No response
Verification
Description / Steps to reproduce the issue
Some lower-half implementations of the I2S driver do not follow the correct return contract.
For instance,
i2s_txsampleraterequires the return value to be the current bitrate. However, some drivers (i.e.rp2040_i2s.c) return 0 on success and a negated errno value on failure. This is not correct, it should be the bitrate on success.nuttx/arch/arm/src/rp2040/rp2040_i2s.c
Lines 737 to 766 in e9ac37e
nuttx/include/nuttx/audio/i2s.h
Lines 268 to 287 in e9ac37e
On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
Arch Linux
NuttX Version
master
Issue Architecture
[Arch: all]
Issue Area
[Area: Drivers]
Host information
No response
Verification