From: Dan Carpenter <dan.carpenter@oracle.com>
To: SF Markus Elfring <elfring@users.sourceforge.net>
Cc: dri-devel@lists.freedesktop.org,
linux-renesas-soc@vger.kernel.org,
David Airlie <airlied@linux.ie>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 1/2] drm/rcar-du: Use common error handling code in rcar_du_encoders_init()
Date: Wed, 25 Oct 2017 09:01:04 +0300 [thread overview]
Message-ID: <20171025060104.vlk546frvmjici37@mwanda> (raw)
In-Reply-To: <9fafa688-f699-c587-ef77-840efa71bf76@users.sourceforge.net>
This is a subtle thing but my preference on this type of thing is the
way the original code is written. I'm still slightly annoyed that
someone once made me rewrite a patch using the new style... But anyways
I guess other people sometimes disagree with me.
Unwinding is for when you allocate five things in a row. You have
to undo four if the last allocation fails. But say you have to take a
lock part way through and drop it before the end of the function. The
lock/unlock is not part of the list of five resources that you want the
function to take so it doesn't belong in the unwind code.
If you add the lock/unlock to the unwind code, then it makes things a
bit tricky because then you have to do funny things like:
free_four:
free(four);
goto free_three: <-- little bunny hop
unlock: <-- less useful label
unlock();
free_three:
free_three();
free_two:
free(two);
free_one:
free(one);
return ret;
It's better to just do the unlocking before the goto. That way the
lock and unlock are close together.
if (!four) {
unlock();
ret = -EFAIL;
goto free_three;
}
Of course, having a big unlock label makes sense if you take a lock at
the start of the function and need to drop it at the end. But in this
case we are taking a lock then dropping it, and taking the next, then
dropping it and so on. It's a different situation.
regards,
dan carpenter
next prev parent reply other threads:[~2017-10-25 6:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-24 16:00 [PATCH 0/2] R-Car Display Unit: Fine-tuning for some function implementations SF Markus Elfring
2017-10-24 16:01 ` [PATCH 1/2] drm/rcar-du: Use common error handling code in rcar_du_encoders_init() SF Markus Elfring
2017-10-25 6:01 ` Dan Carpenter [this message]
2017-10-25 6:35 ` Clarification for approaches around exception handling SF Markus Elfring
2017-10-26 12:40 ` [PATCH 1/2] drm/rcar-du: Use common error handling code in rcar_du_encoders_init() kbuild test robot
2017-11-01 15:38 ` [PATCH v2 0/2] R-Car Display Unit: Fine-tuning for some function implementations SF Markus Elfring
2017-11-01 15:39 ` [PATCH v2 1/2] drm/rcar-du: Use common error handling code in rcar_du_encoders_init() SF Markus Elfring
2017-11-01 15:41 ` [PATCH v2 2/2] drm/rcar-du: Adjust 14 checks for null pointers SF Markus Elfring
2017-10-27 18:45 ` [PATCH 1/2] drm/rcar-du: Use common error handling code in rcar_du_encoders_init() Jani Nikula
2017-10-29 11:01 ` Geert Uytterhoeven
2017-10-29 17:12 ` Laurent Pinchart
2017-10-29 18:19 ` SF Markus Elfring
2017-10-30 9:52 ` [PATCH 1/2] " Jani Nikula
2017-10-30 10:03 ` SF Markus Elfring
2017-10-30 13:18 ` [PATCH 1/2] " Laurent Pinchart
2017-10-24 16:02 ` [PATCH 2/2] drm/rcar-du: Adjust 14 checks for null pointers SF Markus Elfring
2017-10-25 6:02 ` Dan Carpenter
2017-10-25 6:44 ` SF Markus Elfring
2017-10-25 7:32 ` Dan Carpenter
2017-10-25 7:39 ` Unicode characters in commit messages? SF Markus Elfring
2017-10-25 8:43 ` Dan Carpenter
2017-10-25 9:16 ` SF Markus Elfring
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=20171025060104.vlk546frvmjici37@mwanda \
--to=dan.carpenter@oracle.com \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.freedesktop.org \
--cc=elfring@users.sourceforge.net \
--cc=kernel-janitors@vger.kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
/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