From: Shuah Khan <shuahkh@osg.samsung.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: mchehab@osg.samsung.com, tiwai@suse.com, clemens@ladisch.de,
hans.verkuil@cisco.com, laurent.pinchart@ideasonboard.com,
sakari.ailus@linux.intel.com, javier@osg.samsung.com,
pawel@osciak.com, m.szyprowski@samsung.com,
kyungmin.park@samsung.com, perex@perex.cz, arnd@arndb.de,
tvboxspy@gmail.com, crope@iki.fi, ruchandani.tina@gmail.com,
corbet@lwn.net, chehabrafael@gmail.com, k.kozlowski@samsung.com,
stefanr@s5r6.in-berlin.de, inki.dae@samsung.com,
jh1009.sung@samsung.com, elfring@users.sourceforge.net,
prabhakar.csengg@gmail.com, sw0312.kim@samsung.com,
p.zabel@pengutronix.de, ricardo.ribalda@gmail.com,
labbott@fedoraproject.org, pierre-louis.bossart@linux.intel.com,
ricard.wanderlof@axis.com, julian@jusst.de,
takamichiho@gmail.com, dominic.sacre@gmx.de, misterpib@gmail.com,
daniel@zonque.org, gtmkramer@xs4all.nl, normalperson@yhbt.net,
joe@oampo.co.uk, linuxbugs@vittga
Subject: Re: [PATCH v5 22/22] sound/usb: Use Media Controller API to share media resources
Date: Thu, 3 Mar 2016 07:25:37 -0700 [thread overview]
Message-ID: <56D84961.9050902@osg.samsung.com> (raw)
In-Reply-To: <20160303103637.GW5273@mwanda>
On 03/03/2016 03:36 AM, Dan Carpenter wrote:
> On Wed, Mar 02, 2016 at 03:57:03PM -0700, Shuah Khan wrote:
>> On 03/02/2016 01:41 PM, Dan Carpenter wrote:
>>> On Wed, Mar 02, 2016 at 09:50:31AM -0700, Shuah Khan wrote:
>>>> + mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
>>>> + if (!mctl)
>>>> + return -ENOMEM;
>>>> +
>>>> + mctl->media_dev = mdev;
>>>> + if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
>>>> + intf_type = MEDIA_INTF_T_ALSA_PCM_PLAYBACK;
>>>> + mctl->media_entity.function = MEDIA_ENT_F_AUDIO_PLAYBACK;
>>>> + mctl->media_pad.flags = MEDIA_PAD_FL_SOURCE;
>>>> + mixer_pad = 1;
>>>> + } else {
>>>> + intf_type = MEDIA_INTF_T_ALSA_PCM_CAPTURE;
>>>> + mctl->media_entity.function = MEDIA_ENT_F_AUDIO_CAPTURE;
>>>> + mctl->media_pad.flags = MEDIA_PAD_FL_SINK;
>>>> + mixer_pad = 2;
>>>> + }
>>>> + mctl->media_entity.name = pcm->name;
>>>> + media_entity_pads_init(&mctl->media_entity, 1, &mctl->media_pad);
>>>> + ret = media_device_register_entity(mctl->media_dev,
>>>> + &mctl->media_entity);
>>>> + if (ret)
>>>> + goto err1;
>>>
>>> Could we give this label a meaningful name instead of a number?
>>> goto free_mctl;
>>
>> I do see other places where numbered labels are used.
>
> Yeah. But it's the wrong idea. If you remove a label then you have to
> renumber everything. Plus it doesn't say what the goto does.
>
>> Names might help with code readability.
>>
>> register_entity_fail probably makes more sense as a
>> label than free_mctl.
>
> A lot of people do that but the you wind up with code like:
>
> foo = whatever_register();
> if (!foo)
> goto whatever_failed;
>
> if (something_else)
> goto whatever_failed;
>
> So it doesn't make sense. Also it doesn't tell you what the goto does.
> (You can already see that whatever_failed from looking at the if
> statement on the line before.) This function is larger than a page so
> you have to flip down to the other page to see what the goto does, then
> you have to flip back and find your place again. But if the label says
> what the goto does then you can just say, "Have we allocated anything
> since mctl? No, then freeing mctl is the right thing." You don't need
> to flip to the othe page.
>
Yeah. You are right about large routines and needing
to check labels. I will fix it in a followup patch.
thanks,
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978
WARNING: multiple messages have this Message-ID (diff)
From: Shuah Khan <shuahkh@osg.samsung.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: mchehab@osg.samsung.com, tiwai@suse.com, clemens@ladisch.de,
hans.verkuil@cisco.com, laurent.pinchart@ideasonboard.com,
sakari.ailus@linux.intel.com, javier@osg.samsung.com,
pawel@osciak.com, m.szyprowski@samsung.com,
kyungmin.park@samsung.com, perex@perex.cz, arnd@arndb.de,
tvboxspy@gmail.com, crope@iki.fi, ruchandani.tina@gmail.com,
corbet@lwn.net, chehabrafael@gmail.com, k.kozlowski@samsung.com,
stefanr@s5r6.in-berlin.de, inki.dae@samsung.com,
jh1009.sung@samsung.com, elfring@users.sourceforge.net,
prabhakar.csengg@gmail.com, sw0312.kim@samsung.com,
p.zabel@pengutronix.de, ricardo.ribalda@gmail.com,
labbott@fedoraproject.org, pierre-louis.bossart@linux.intel.com,
ricard.wanderlof@axis.com, julian@jusst.de,
takamichiho@gmail.com, dominic.sacre@gmx.de, misterpib@gmail.com,
daniel@zonque.org, gtmkramer@xs4all.nl, normalperson@yhbt.net,
joe@oampo.co.uk, linuxbugs@vittgam.net, johan@oljud.se,
klock.android@gmail.com, nenggun.kim@samsung.com,
j.anaszewski@samsung.com, geliangtang@163.com,
albert@huitsing.nl, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, alsa-devel@alsa-project.org,
Shuah Khan <shuahkh@osg.samsung.com>
Subject: Re: [PATCH v5 22/22] sound/usb: Use Media Controller API to share media resources
Date: Thu, 3 Mar 2016 07:25:37 -0700 [thread overview]
Message-ID: <56D84961.9050902@osg.samsung.com> (raw)
In-Reply-To: <20160303103637.GW5273@mwanda>
On 03/03/2016 03:36 AM, Dan Carpenter wrote:
> On Wed, Mar 02, 2016 at 03:57:03PM -0700, Shuah Khan wrote:
>> On 03/02/2016 01:41 PM, Dan Carpenter wrote:
>>> On Wed, Mar 02, 2016 at 09:50:31AM -0700, Shuah Khan wrote:
>>>> + mctl = kzalloc(sizeof(*mctl), GFP_KERNEL);
>>>> + if (!mctl)
>>>> + return -ENOMEM;
>>>> +
>>>> + mctl->media_dev = mdev;
>>>> + if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
>>>> + intf_type = MEDIA_INTF_T_ALSA_PCM_PLAYBACK;
>>>> + mctl->media_entity.function = MEDIA_ENT_F_AUDIO_PLAYBACK;
>>>> + mctl->media_pad.flags = MEDIA_PAD_FL_SOURCE;
>>>> + mixer_pad = 1;
>>>> + } else {
>>>> + intf_type = MEDIA_INTF_T_ALSA_PCM_CAPTURE;
>>>> + mctl->media_entity.function = MEDIA_ENT_F_AUDIO_CAPTURE;
>>>> + mctl->media_pad.flags = MEDIA_PAD_FL_SINK;
>>>> + mixer_pad = 2;
>>>> + }
>>>> + mctl->media_entity.name = pcm->name;
>>>> + media_entity_pads_init(&mctl->media_entity, 1, &mctl->media_pad);
>>>> + ret = media_device_register_entity(mctl->media_dev,
>>>> + &mctl->media_entity);
>>>> + if (ret)
>>>> + goto err1;
>>>
>>> Could we give this label a meaningful name instead of a number?
>>> goto free_mctl;
>>
>> I do see other places where numbered labels are used.
>
> Yeah. But it's the wrong idea. If you remove a label then you have to
> renumber everything. Plus it doesn't say what the goto does.
>
>> Names might help with code readability.
>>
>> register_entity_fail probably makes more sense as a
>> label than free_mctl.
>
> A lot of people do that but the you wind up with code like:
>
> foo = whatever_register();
> if (!foo)
> goto whatever_failed;
>
> if (something_else)
> goto whatever_failed;
>
> So it doesn't make sense. Also it doesn't tell you what the goto does.
> (You can already see that whatever_failed from looking at the if
> statement on the line before.) This function is larger than a page so
> you have to flip down to the other page to see what the goto does, then
> you have to flip back and find your place again. But if the label says
> what the goto does then you can just say, "Have we allocated anything
> since mctl? No, then freeing mctl is the right thing." You don't need
> to flip to the othe page.
>
Yeah. You are right about large routines and needing
to check labels. I will fix it in a followup patch.
thanks,
-- Shuah
--
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978
next prev parent reply other threads:[~2016-03-03 14:25 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-02 16:50 [PATCH v5 22/22] sound/usb: Use Media Controller API to share media resources Shuah Khan
2016-03-02 16:50 ` Shuah Khan
2016-03-02 20:41 ` Dan Carpenter
2016-03-02 20:41 ` Dan Carpenter
2016-03-02 22:57 ` Shuah Khan
2016-03-02 22:57 ` Shuah Khan
2016-03-03 10:36 ` Dan Carpenter
2016-03-03 10:36 ` Dan Carpenter
2016-03-03 14:25 ` Shuah Khan [this message]
2016-03-03 14:25 ` Shuah Khan
2016-03-03 18:21 ` Mauro Carvalho Chehab
2016-03-03 18:21 ` Mauro Carvalho Chehab
2016-03-03 19:06 ` Shuah Khan
2016-03-03 19:06 ` Shuah Khan
2016-03-05 10:00 ` Mauro Carvalho Chehab
2016-03-05 10:00 ` Mauro Carvalho Chehab
2016-03-07 14:16 ` Shuah Khan
2016-03-07 14:16 ` Shuah Khan
2016-03-07 20:03 ` Shuah Khan
2016-03-07 20:03 ` Shuah Khan
2016-03-07 22:06 ` Shuah Khan
2016-03-07 22:06 ` Shuah Khan
2016-03-07 22:10 ` Shuah Khan
2016-03-07 22:10 ` Shuah Khan
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=56D84961.9050902@osg.samsung.com \
--to=shuahkh@osg.samsung.com \
--cc=arnd@arndb.de \
--cc=chehabrafael@gmail.com \
--cc=clemens@ladisch.de \
--cc=corbet@lwn.net \
--cc=crope@iki.fi \
--cc=dan.carpenter@oracle.com \
--cc=daniel@zonque.org \
--cc=dominic.sacre@gmx.de \
--cc=elfring@users.sourceforge.net \
--cc=gtmkramer@xs4all.nl \
--cc=hans.verkuil@cisco.com \
--cc=inki.dae@samsung.com \
--cc=javier@osg.samsung.com \
--cc=jh1009.sung@samsung.com \
--cc=joe@oampo.co.uk \
--cc=julian@jusst.de \
--cc=k.kozlowski@samsung.com \
--cc=kyungmin.park@samsung.com \
--cc=labbott@fedoraproject.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linuxbugs@vittga \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@osg.samsung.com \
--cc=misterpib@gmail.com \
--cc=normalperson@yhbt.net \
--cc=p.zabel@pengutronix.de \
--cc=pawel@osciak.com \
--cc=perex@perex.cz \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=prabhakar.csengg@gmail.com \
--cc=ricard.wanderlof@axis.com \
--cc=ricardo.ribalda@gmail.com \
--cc=ruchandani.tina@gmail.com \
--cc=sakari.ailus@linux.intel.com \
--cc=stefanr@s5r6.in-berlin.de \
--cc=sw0312.kim@samsung.com \
--cc=takamichiho@gmail.com \
--cc=tiwai@suse.com \
--cc=tvboxspy@gmail.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.