Make code more readable by not using the return value of the WARN() macro. Set ret variable in an undefined case.
Message ID | 201105231307.53836.hselasky@c2i.net (mailing list archive) |
---|---|
State | Superseded, archived |
Headers |
Return-path: <mchehab@pedra> Envelope-to: mchehab@pedra Delivery-date: Mon, 23 May 2011 08:10:17 -0300 Received: from mchehab by pedra with local (Exim 4.72) (envelope-from <mchehab@pedra>) id 1QOT1c-0006AV-Q8 for mchehab@pedra; Mon, 23 May 2011 08:10:17 -0300 Received: from casper.infradead.org [85.118.1.10] by pedra with IMAP (fetchmail-6.3.17) for <mchehab@localhost> (single-drop); Mon, 23 May 2011 08:10:16 -0300 (BRT) Received: from vger.kernel.org ([209.132.180.67]) by casper.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QOT0n-0008Nh-1Z; Mon, 23 May 2011 11:09:25 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752438Ab1EWLJI (ORCPT <rfc822; kmpark@infradead.org> + 1 other); Mon, 23 May 2011 07:09:08 -0400 Received: from mailfe01.c2i.net ([212.247.154.2]:56095 "EHLO swip.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752209Ab1EWLJI (ORCPT <rfc822;linux-media@vger.kernel.org>); Mon, 23 May 2011 07:09:08 -0400 X-Cloudmark-Score: 0.000000 [] X-Cloudmark-Analysis: v=1.1 cv=1W/zHQV/91afZrGZjnmxK4mmm0xPtKVmshL3njyU5IE= c=1 sm=1 a=JiQMv8R4MQIA:10 a=WQU8e4WWZSUA:10 a=CL8lFSKtTFcA:10 a=i9M/sDlu2rpZ9XS819oYzg==:17 a=SObZXD9RMCsnjX8LmoMA:9 a=CjuIK1q_8ugA:10 a=8kQB0OdkAAAA:8 a=5ucU0ciSJY5wC_JzGU8A:9 a=9aOQ2cSd83gA:10 a=i9M/sDlu2rpZ9XS819oYzg==:117 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mailfe01.swip.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.1 X-TFF-CGPSA-Version: 1.7 X-T2-CGPSA-Filter: Scanned Received: from [188.126.198.129] (account mc467741@c2i.net HELO laptop002.hselasky.homeunix.org) by mailfe01.swip.net (CommuniGate Pro SMTP 5.2.19) with ESMTPA id 130885811; Mon, 23 May 2011 13:09:04 +0200 To: "linux-media@vger.kernel.org" <linux-media@vger.kernel.org> Subject: [PATCH] Make code more readable by not using the return value of the WARN() macro. Set ret variable in an undefined case. Cc: Mauro Carvalho Chehab <mchehab@redhat.com> From: Hans Petter Selasky <hselasky@c2i.net> X-Face: *nPdTl_}RuAI6^PVpA02T?$%Xa^>@hE0uyUIoiha$pC:9TVgl.Oq,NwSZ4V" =?iso-8859-15?q?=7CLR=2E+tj=7Dg5=0A=09=25V?=,x^qOs~mnU3]Gn; cQLv&.N>TrxmSFf+p6(30a/{)KUU!s}w\IhQBj}[g}bj0I3^glmC( =?iso-8859-15?q?=0A=09=3AAuzV9=3A=2EhESm-x4h240C=609=3Dw?= Date: Mon, 23 May 2011 13:07:53 +0200 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_JAk2NFgVtFEQdpE" Message-Id: <201105231307.53836.hselasky@c2i.net> Precedence: bulk List-ID: <linux-media.vger.kernel.org> X-Mailing-List: linux-media@vger.kernel.org Sender: <mchehab@pedra> |
Commit Message
Hans Petter Selasky
May 23, 2011, 11:07 a.m. UTC
--HPS
Comments
Please, inline patches. Otherwise, this is what one gets, when replying. On Mon, 23 May 2011, Hans Petter Selasky wrote: > --HPS > In any case, just throwing in my 2 cents - no idea how not using the return value of WARN() makes code more readable. On the contrary, using it is a standard practice. This patch doesn't seem like an improvement to me. Thanks Guennadi --- Guennadi Liakhovetski, Ph.D. Freelance Open-Source Software Developer http://www.open-technology.de/ -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Monday 23 May 2011 20:22:02 Guennadi Liakhovetski wrote: > Please, inline patches. Otherwise, this is what one gets, when replying. > > On Mon, 23 May 2011, Hans Petter Selasky wrote: > > --HPS > > In any case, just throwing in my 2 cents - no idea how not using the > return value of WARN() makes code more readable. On the contrary, using it > is a standard practice. This patch doesn't seem like an improvement to me. There is no strong reason for the WARN() part, you may ignore that, but the ret = 0, part is still valid. Should I generate a new patch or can you handle this? --HPS -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Em 23-05-2011 16:04, Hans Petter Selasky escreveu: > On Monday 23 May 2011 20:22:02 Guennadi Liakhovetski wrote: >> Please, inline patches. Otherwise, this is what one gets, when replying. >> >> On Mon, 23 May 2011, Hans Petter Selasky wrote: >>> --HPS >> >> In any case, just throwing in my 2 cents - no idea how not using the >> return value of WARN() makes code more readable. On the contrary, using it >> is a standard practice. This patch doesn't seem like an improvement to me. > > There is no strong reason for the WARN() part, you may ignore that, but the > ret = 0, part is still valid. Should I generate a new patch or can you handle > this? Em 23-05-2011 08:07, Hans Petter Selasky escreveu: > --HPS > > > dvb-usb-0005.patch > > > From 94b88b92763f9309018ba04c200a8842ce1ff0ed Mon Sep 17 00:00:00 2001 > From: Hans Petter Selasky <hselasky@c2i.net> > Date: Mon, 23 May 2011 13:07:08 +0200 > Subject: [PATCH] Make code more readable by not using the return value of the WARN() macro. Set ret variable in an undefined case. > > Signed-off-by: Hans Petter Selasky <hselasky@c2i.net> > --- > drivers/media/video/sr030pc30.c | 5 ++++- > 1 files changed, 4 insertions(+), 1 deletions(-) > > diff --git a/drivers/media/video/sr030pc30.c b/drivers/media/video/sr030pc30.c > index c901721..6cc64c9 100644 > --- a/drivers/media/video/sr030pc30.c > +++ b/drivers/media/video/sr030pc30.c > @@ -726,8 +726,10 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on) > const struct sr030pc30_platform_data *pdata = info->pdata; > int ret; > > - if (WARN(pdata == NULL, "No platform data!\n")) > + if (pdata == NULL) { > + WARN(1, "No platform data!\n"); > return -ENOMEM; > + } > > /* > * Put sensor into power sleep mode before switching off > @@ -746,6 +748,7 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on) > if (on) { > ret = sr030pc30_base_config(sd); > } else { > + ret = 0; > info->curr_win = NULL; > info->curr_fmt = NULL; > } > -- 1.7.1.1 IMHO, both hunks make sense, as, on the first hunk, it is returning an error condition. Yet, -ENOMEM seems to be the wrong return code. -EINVAL is probably more appropriate. However, the patch is badly described. It is not about making the code cleaner, but about avoiding to run s_power if no platform data is found, and to avoid having ret undefined. Eventually, it should be broken into two different patches, as they fix different things. Please, when sending us patches, provide a proper description with "what" information at the first line, and why and how at the patch descriptions. Please, also avoid to have any line bigger than 74 characters, otherwise they'll look weird when seeing the patch history. Thanks, Mauro. information a -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 25 May 2011, Mauro Carvalho Chehab wrote: > Em 23-05-2011 16:04, Hans Petter Selasky escreveu: > > On Monday 23 May 2011 20:22:02 Guennadi Liakhovetski wrote: > >> Please, inline patches. Otherwise, this is what one gets, when replying. > >> > >> On Mon, 23 May 2011, Hans Petter Selasky wrote: > >>> --HPS > >> > >> In any case, just throwing in my 2 cents - no idea how not using the > >> return value of WARN() makes code more readable. On the contrary, using it > >> is a standard practice. This patch doesn't seem like an improvement to me. > > > > There is no strong reason for the WARN() part, you may ignore that, but the > > ret = 0, part is still valid. Should I generate a new patch or can you handle > > this? > Em 23-05-2011 08:07, Hans Petter Selasky escreveu: > > --HPS > > > > > > dvb-usb-0005.patch > > > > > > From 94b88b92763f9309018ba04c200a8842ce1ff0ed Mon Sep 17 00:00:00 2001 > > From: Hans Petter Selasky <hselasky@c2i.net> > > Date: Mon, 23 May 2011 13:07:08 +0200 > > Subject: [PATCH] Make code more readable by not using the return value of the WARN() macro. Set ret variable in an undefined case. > > > > Signed-off-by: Hans Petter Selasky <hselasky@c2i.net> > > --- > > drivers/media/video/sr030pc30.c | 5 ++++- > > 1 files changed, 4 insertions(+), 1 deletions(-) > > > > diff --git a/drivers/media/video/sr030pc30.c b/drivers/media/video/sr030pc30.c > > index c901721..6cc64c9 100644 > > --- a/drivers/media/video/sr030pc30.c > > +++ b/drivers/media/video/sr030pc30.c > > @@ -726,8 +726,10 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on) > > const struct sr030pc30_platform_data *pdata = info->pdata; > > int ret; > > > > - if (WARN(pdata == NULL, "No platform data!\n")) > > + if (pdata == NULL) { > > + WARN(1, "No platform data!\n"); > > return -ENOMEM; > > + } > > > > /* > > * Put sensor into power sleep mode before switching off > > @@ -746,6 +748,7 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on) > > if (on) { > > ret = sr030pc30_base_config(sd); > > } else { > > + ret = 0; > > info->curr_win = NULL; > > info->curr_fmt = NULL; > > } > > -- 1.7.1.1 > > IMHO, both hunks make sense, as, on the first hunk, it is returning an error condition. > Yet, -ENOMEM seems to be the wrong return code. -EINVAL is probably more appropriate. Sorry, Mauro, don't understand. AFAICS, the first hunk makes _no_ functional difference, it only obfuscates a perfectly valid use of the WARN() macro. Thanks Guennadi > > However, the patch is badly described. It is not about making the code cleaner, but > about avoiding to run s_power if no platform data is found, and to avoid having > ret undefined. Eventually, it should be broken into two different patches, as they > fix different things. > > Please, when sending us patches, provide a proper description with "what" information > at the first line, and why and how at the patch descriptions. Please, also avoid to > have any line bigger than 74 characters, otherwise they'll look weird when seeing the > patch history. > > Thanks, > Mauro. > information a > --- Guennadi Liakhovetski, Ph.D. Freelance Open-Source Software Developer http://www.open-technology.de/ -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From 94b88b92763f9309018ba04c200a8842ce1ff0ed Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky <hselasky@c2i.net> Date: Mon, 23 May 2011 13:07:08 +0200 Subject: [PATCH] Make code more readable by not using the return value of the WARN() macro. Set ret variable in an undefined case. Signed-off-by: Hans Petter Selasky <hselasky@c2i.net> --- drivers/media/video/sr030pc30.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/drivers/media/video/sr030pc30.c b/drivers/media/video/sr030pc30.c index c901721..6cc64c9 100644 --- a/drivers/media/video/sr030pc30.c +++ b/drivers/media/video/sr030pc30.c @@ -726,8 +726,10 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on) const struct sr030pc30_platform_data *pdata = info->pdata; int ret; - if (WARN(pdata == NULL, "No platform data!\n")) + if (pdata == NULL) { + WARN(1, "No platform data!\n"); return -ENOMEM; + } /* * Put sensor into power sleep mode before switching off @@ -746,6 +748,7 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on) if (on) { ret = sr030pc30_base_config(sd); } else { + ret = 0; info->curr_win = NULL; info->curr_fmt = NULL; } -- 1.7.1.1