On Thu, Sep 4, 2008 at 4:43 PM, Mark Brown
<[email protected]> wrote:
>
> On Thu, Sep 04, 2008 at 04:22:06PM +0800, Bryan Wu wrote:
> > From: Cliff Cai <[email protected]>
> >
> > Signed-off-by: Cliff Cai <[email protected]>
> > Signed-off-by: Bryan Wu <[email protected]>
>
> Acked-by: Mark Brown <[email protected]>
>
> Please fix the minor issues below as incremental patches for ease of
> review.
>
> > + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
> > + case SND_SOC_DAIFMT_I2S:
> > + break;
> > + case SND_SOC_DAIFMT_LEFT_J:
> > + ret = -EINVAL;
> > + break;
> > + }
>
> The SND_SOC_DAFIMT_LEFT_J: ought to be default: instead - there's more
> DAI formats than just that.
>
> > + if (!bf5xx_i2s.master) {
> > + /*
> > + * TX and RX are not independent,they are enabled at the same time,
> > + * even if only one side is running.So,we need to configure both of
> > + * them in advance.
> > + *
> > + * CPU DAI format:I2S, slave mode.
> > + */
+ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+ case SND_SOC_DAIFMT_CBS_CFS:
+ ret = -EINVAL;
+ break;
+ case SND_SOC_DAIFMT_CBM_CFS:
+ ret = -EINVAL;
+ break;
+ case SND_SOC_DAIFMT_CBM_CFM:
+ break;
+ case SND_SOC_DAIFMT_CBS_CFM:
+ ret = -EINVAL;
+ break;
+ default:
+ break;
+ }
My eyes fell upon this switch statement, probably I have similar
criticisms as to what has already been said, but:
1. Surely the default case is also an -EINVAL
2. Why not let all the EINVALS fall through, it will shorten up the
code, and IMO make it more readable, something like this?
+ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+ case SND_SOC_DAIFMT_CBM_CFM: /* Passing Case */
+ break;
+ case SND_SOC_DAIFMT_CBS_CFS: /* Failing Cases */
+ case SND_SOC_DAIFMT_CBM_CFS:
+ case SND_SOC_DAIFMT_CBS_CFM:
+ ret = -EINVAL;
+ break;
+ default:
+ printk(KERN_INFO "Unknown SND_SOC_DAIFMT kind\n");
+ ret = -EINVAL;
+ break;
+ }
On Thu, 09 Oct 2008 08:58:08 +0200, John Kacur said:
> My eyes fell upon this switch statement, probably I have similar
> criticisms as to what has already been said, but:
> 1. Surely the default case is also an -EINVAL
> 2. Why not let all the EINVALS fall through, it will shorten up the
> code, and IMO make it more readable, something like this?
> + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
> + case SND_SOC_DAIFMT_CBM_CFM: /* Passing Case */
> + break;
> + case SND_SOC_DAIFMT_CBS_CFS: /* Failing Cases */
> + case SND_SOC_DAIFMT_CBM_CFS:
> + case SND_SOC_DAIFMT_CBS_CFM:
> + ret = -EINVAL;
> + break;
> + default:
> + printk(KERN_INFO "Unknown SND_SOC_DAIFMT kind\n");
> + ret = -EINVAL;
> + break;
> + }
Even shorter, but puts the default in a non-standard place:
+ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+ case SND_SOC_DAIFMT_CBM_CFM: /* Passing Case */
+ break;
+ default: /* So much Fail we should say something */
+ printk(KERN_INFO "Unknown SND_SOC_DAIFMT kind\n");
+ case SND_SOC_DAIFMT_CBS_CFS: /* Failing Cases */
+ case SND_SOC_DAIFMT_CBM_CFS:
+ case SND_SOC_DAIFMT_CBS_CFM:
+ ret = -EINVAL;
+ break;
+ }
(I see a checkpatch update to check where default: is, coming in 3.. 2.. 1.. :)
On Thu, Oct 9, 2008 at 9:35 AM, <[email protected]> wrote:
> On Thu, 09 Oct 2008 08:58:08 +0200, John Kacur said:
>
>> My eyes fell upon this switch statement, probably I have similar
>> criticisms as to what has already been said, but:
>> 1. Surely the default case is also an -EINVAL
>> 2. Why not let all the EINVALS fall through, it will shorten up the
>> code, and IMO make it more readable, something like this?
>> + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
>> + case SND_SOC_DAIFMT_CBM_CFM: /* Passing Case */
>> + break;
>> + case SND_SOC_DAIFMT_CBS_CFS: /* Failing Cases */
>> + case SND_SOC_DAIFMT_CBM_CFS:
>> + case SND_SOC_DAIFMT_CBS_CFM:
>> + ret = -EINVAL;
>> + break;
>> + default:
>> + printk(KERN_INFO "Unknown SND_SOC_DAIFMT kind\n");
>> + ret = -EINVAL;
>> + break;
>> + }
>
> Even shorter, but puts the default in a non-standard place:
>
> + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
> + case SND_SOC_DAIFMT_CBM_CFM: /* Passing Case */
> + break;
> + default: /* So much Fail we should say something */
> + printk(KERN_INFO "Unknown SND_SOC_DAIFMT kind\n");
> + case SND_SOC_DAIFMT_CBS_CFS: /* Failing Cases */
> + case SND_SOC_DAIFMT_CBM_CFS:
> + case SND_SOC_DAIFMT_CBS_CFM:
> + ret = -EINVAL;
> + break;
> + }
>
> (I see a checkpatch update to check where default: is, coming in 3.. 2.. 1.. :)
>
Well, of course you only want to make things shorter when it increases
clarity, you don't want to make things shorter for the sake of making
them shorter, so yeah, I would nix that non-standard default position
too.
On Thu, Oct 09, 2008 at 08:58:08AM +0200, John Kacur wrote:
> On Thu, Sep 4, 2008 at 4:43 PM, Mark Brown
> <[email protected]> wrote:
> code, and IMO make it more readable, something like this?
> + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
> + case SND_SOC_DAIFMT_CBM_CFM: /* Passing Case */
> + break;
> + case SND_SOC_DAIFMT_CBS_CFS: /* Failing Cases */
> + case SND_SOC_DAIFMT_CBM_CFS:
> + case SND_SOC_DAIFMT_CBS_CFM:
> + ret = -EINVAL;
> + break;
> + default:
> + printk(KERN_INFO "Unknown SND_SOC_DAIFMT kind\n");
> + ret = -EINVAL;
> + break;
> + }
Yes, that's better - I'd remove the comments (they don't add much) and
the prinkt() should be a KERN_ERR or higher severity since this should
only happen as a result of a buggy machine driver. You could also just
have a single default: for the unsupported types.