mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	dri-devel@lists.freedesktop.org,
	linux-renesas-soc@vger.kernel.org
Cc: David Airlie <airlied@linux.ie>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org
Subject: Re: Clarification for approaches around exception handling
Date: Wed, 25 Oct 2017 08:35:19 +0200	[thread overview]
Message-ID: <1c595ff5-9534-2b3f-38d4-970418ed8b25@users.sourceforge.net> (raw)
In-Reply-To: <20171025060104.vlk546frvmjici37@mwanda>

> But anyways I guess other people sometimes disagree with me.

Am I one of them?   ;-)


> Unwinding is for when you allocate five things in a row.

This is a general issue.

I find that it is also needed in this function as usual.


> You have to undo four if the last allocation fails.

Concrete numbers might help to clarify another example.


> 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.

Such a view is useful to some degree.


> 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.

I would prefer to store such an action also only so often in the code
as it is really required.


> That way the lock and unlock are close together.

It might look nice occasionally.


> 	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.

Lock scopes can interfere with a preferred control flow, can't they?


I have got the impression that your detailed reply could have been
more appropriate for update suggestions around other software modules.

Regards,
Markus

  reply	other threads:[~2017-10-25  6:37 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
2017-10-25  6:35     ` SF Markus Elfring [this message]
2017-10-26 12:40   ` 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=1c595ff5-9534-2b3f-38d4-970418ed8b25@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=airlied@linux.ie \
    --cc=dan.carpenter@oracle.com \
    --cc=dri-devel@lists.freedesktop.org \
    --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

Powered by JetHome