Message ID | 20231211175023.1680247-6-mike.rudenko@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230286vqy; Mon, 11 Dec 2023 09:51:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IESsdP+WCZo1soRJ9kGKXnjfe5+iakHAi6wcA/OD6gSsgDcSQl2VljYNSFBIB73fXttCtDs X-Received: by 2002:a05:6a00:2d9e:b0:6ce:2731:5f70 with SMTP id fb30-20020a056a002d9e00b006ce27315f70mr2495945pfb.47.1702317081028; Mon, 11 Dec 2023 09:51:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317081; cv=none; d=google.com; s=arc-20160816; b=tw8QPRxg/TnNgJkkFvFb+msgLVvpHzX+miSo+RsjQSoW5CWIi8GtoUFJV7YSKu9zs4 R/e+qcW5mGL84TfI/AIlGTb/O7FQz8/prHtak6P6s/jTLu5G1YZcfoF8ioOiz/5w5eVT IsnxtYs02Ne1OCzFYvsSSRpKUwXY4VMZiLk4TW6IuKweeDKbZbaxJd7xCsneF8xeBGBu +zZd/46j4/VCZTG+PU7woermF5ZkuGnyCeUVD1tTXH+yzYL1Eq4UisfHgsp4oLuYHMlL pDCsBZCF63MYWu/9qHGfy5UADU19XIBCDWWPsxUxu2gtS9DpoeWvvPE2n24SPqvbZWZY tPhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e4fte2YHRSrHHN42OBWruBtaIGZ/SFtVFuhUHEuhcX8=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=cNUzJWASUyIH/Q2KndBC68/lgQOF6hpuNqVNrhiOWdEVvdLYC0hMDWbnjvT8sxOFmd rY3LDf69nRJ/uVTAluac0AMwqFxFC8RjonkgmqhtHxPcZ87p4/JwetpJiCzHgMd+U7ms CKT8+1KKsEUheHWWNFfltW4p5h3r9QkDXISNk7A7jiOnunKkDn8DO8U/SXUWWrxhw0U1 3F1JVrpnRGnHS31MAWcVrrSStwgOMRE7iK7GVfZ3u9erVgm4dmrA82eUtcZllYYTRtem WQ//vpYOFuY8RkS+xCwugzNZkY9gzxFMPimgBenaitH6o13+DWKEDcmKbzwHheZqIvOO jpEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IqFLlH4h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c29-20020a631c1d000000b005657ba564bdsi6161300pgc.826.2023.12.11.09.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IqFLlH4h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9A02A80564BE; Mon, 11 Dec 2023 09:51:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344965AbjLKRvC (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Mon, 11 Dec 2023 12:51:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345104AbjLKRup (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 11 Dec 2023 12:50:45 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA29AD0; Mon, 11 Dec 2023 09:50:51 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50bf1e32571so5581961e87.2; Mon, 11 Dec 2023 09:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317049; x=1702921849; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e4fte2YHRSrHHN42OBWruBtaIGZ/SFtVFuhUHEuhcX8=; b=IqFLlH4hfcQN+nVLz+K238zJs287ZHvR6ddocANW7MKwC1bTrAp5lE/ASgXEyoUvQl oqEn1zXb5ta+5RjuYRJYTslbWIF26fWJwIcL6ap/MP/12dMZ0yHjQWgvRgygRFfwRMlX AYglRkXztW9Xk/JY6ZzssxWLtktBFOMc0oGesNzaD81QSLZ6Yr1FIV9YlZJ4ZROc6PaC 5Naf2893cI63+ICan4gDM8BnyZ8e1tGTkQzOVOrC0/B/UPw8Y34mU1ow4s0Idtw0hdoO 1rQd0Lr1voyFVAixcFPoObmOuywWf0qbZBlGPd6L/T9WI18C7t0ShOyOvhAhzYTqiBWZ hKvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317049; x=1702921849; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e4fte2YHRSrHHN42OBWruBtaIGZ/SFtVFuhUHEuhcX8=; b=NtReQpCWkpf0gtZGwIPsPKvbmE8UgIlP1rvFea3DF+R4WWiw1xFsrmOLXN7T4yJYVg QRlEZkXI/q5UZP0zLiVgWGdO6vzYxSEEgwH4r2rulSMBTtEd8qqAJj6/ecHu+Ds1/WY1 XlrUgCh+6mxSXthzasazIq/RBhsFh/+Czf8QFUN/G/33U9rroJf6SDzK8dON87ILJUle CP7M0R5c9NqwN9nRW+9LNjJ4feUAwAogal/O+UoaJnXwZmu0+gpKfOniIesJTPbxh+6C w7J3J0BmmqZSLAtD9tdbyyNRWoK13Za+qHLQEauB4LfWVN4wSbEe3fCoPm0sjhcDiTyT pxew== X-Gm-Message-State: AOJu0YxuayilUJAFgHP0X0XA3uephF625qxtVnmVo9znGjKcLHwTbxfc IDGX91YZ6XrJV/IGMnELR3iNUtgtXch1/ozV X-Received: by 2002:ac2:5328:0:b0:50d:ff76:61ee with SMTP id f8-20020ac25328000000b0050dff7661eemr767800lfh.134.1702317049431; Mon, 11 Dec 2023 09:50:49 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id k4-20020a05651210c400b0050bef21a012sm1141582lfg.191.2023.12.11.09.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:48 -0800 (PST) From: Mikhail Rudenko <mike.rudenko@gmail.com> To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sakari Ailus <sakari.ailus@linux.intel.com>, Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Jacopo Mondi <jacopo@jmondi.org>, Tommaso Merciai <tommaso.merciai@amarulasolutions.com>, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, Dave Stevenson <dave.stevenson@raspberrypi.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Mikhail Rudenko <mike.rudenko@gmail.com> Subject: [PATCH 05/19] media: i2c: ov4689: Refactor ov4689_set_ctrl Date: Mon, 11 Dec 2023 20:50:08 +0300 Message-ID: <20231211175023.1680247-6-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231211175023.1680247-1-mike.rudenko@gmail.com> References: <20231211175023.1680247-1-mike.rudenko@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:19 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008835514968282 X-GMAIL-MSGID: 1785008835514968282 |
Series |
Omnivision OV4689 refactoring and improvements
|
|
Commit Message
Mikhail Rudenko
Dec. 11, 2023, 5:50 p.m. UTC
Introduces local variables for regmap and the control value within the
ov4689_set_ctrl function. This adjustment eliminates repetition within
the function.
Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
---
drivers/media/i2c/ov4689.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
Comments
Hi Mikhail, Thank you for the patch. On Mon, Dec 11, 2023 at 08:50:08PM +0300, Mikhail Rudenko wrote: > Introduces local variables for regmap and the control value within the > ov4689_set_ctrl function. This adjustment eliminates repetition within > the function. > > Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com> > --- > drivers/media/i2c/ov4689.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) > > diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c > index 8c120d7f7830..42700ecfbe0e 100644 > --- a/drivers/media/i2c/ov4689.c > +++ b/drivers/media/i2c/ov4689.c > @@ -584,7 +584,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) > { > struct ov4689 *ov4689 = > container_of(ctrl->handler, struct ov4689, ctrl_handler); > + struct regmap *regmap = ov4689->regmap; > struct device *dev = ov4689->dev; > + s32 val = ctrl->val; For ctrl->val, I think the code is clearer without this change. When reading the function, seeing "val", I need to look up what it is, while seeing "ctrl->val" gives me more context and makes (in my opinion) the code more readable. > int sensor_gain; > s64 max_expo; > int ret; > @@ -593,7 +595,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) > switch (ctrl->id) { > case V4L2_CID_VBLANK: > /* Update max exposure while meeting expected vblanking */ > - max_expo = ov4689->cur_mode->height + ctrl->val - 4; > + max_expo = ov4689->cur_mode->height + val - 4; > __v4l2_ctrl_modify_range(ov4689->exposure, > ov4689->exposure->minimum, max_expo, > ov4689->exposure->step, > @@ -607,36 +609,34 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) > switch (ctrl->id) { > case V4L2_CID_EXPOSURE: > /* 4 least significant bits of exposure are fractional part */ > - ret = cci_write(ov4689->regmap, OV4689_REG_EXPOSURE, > - ctrl->val << 4, NULL); > + cci_write(regmap, OV4689_REG_EXPOSURE, val << 4, &ret); > break; > case V4L2_CID_ANALOGUE_GAIN: > - ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain); > + ret = ov4689_map_gain(ov4689, val, &sensor_gain); > > - cci_write(ov4689->regmap, OV4689_REG_GAIN_H, > + cci_write(regmap, OV4689_REG_GAIN_H, > (sensor_gain >> OV4689_GAIN_H_SHIFT) & > OV4689_GAIN_H_MASK, &ret); > > - cci_write(ov4689->regmap, OV4689_REG_GAIN_L, > + cci_write(regmap, OV4689_REG_GAIN_L, > sensor_gain & OV4689_GAIN_L_MASK, > &ret); > break; > case V4L2_CID_VBLANK: > - ret = cci_write(ov4689->regmap, OV4689_REG_VTS, > - ctrl->val + ov4689->cur_mode->height, NULL); > + cci_write(regmap, OV4689_REG_VTS, > + val + ov4689->cur_mode->height, &ret); > break; > case V4L2_CID_TEST_PATTERN: > - ret = ov4689_enable_test_pattern(ov4689, ctrl->val); > + ret = ov4689_enable_test_pattern(ov4689, val); > break; > default: > dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", > - __func__, ctrl->id, ctrl->val); > + __func__, ctrl->id, val); > ret = -EINVAL; > break; > } > > pm_runtime_put(dev); > - > return ret; > } > > -- > 2.43.0 >
On 2023-12-11 at 20:11 +02, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote: > Hi Mikhail, > > Thank you for the patch. > > On Mon, Dec 11, 2023 at 08:50:08PM +0300, Mikhail Rudenko wrote: >> Introduces local variables for regmap and the control value within the >> ov4689_set_ctrl function. This adjustment eliminates repetition within >> the function. >> >> Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com> >> --- >> drivers/media/i2c/ov4689.c | 22 +++++++++++----------- >> 1 file changed, 11 insertions(+), 11 deletions(-) >> >> diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c >> index 8c120d7f7830..42700ecfbe0e 100644 >> --- a/drivers/media/i2c/ov4689.c >> +++ b/drivers/media/i2c/ov4689.c >> @@ -584,7 +584,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) >> { >> struct ov4689 *ov4689 = >> container_of(ctrl->handler, struct ov4689, ctrl_handler); >> + struct regmap *regmap = ov4689->regmap; >> struct device *dev = ov4689->dev; >> + s32 val = ctrl->val; > > For ctrl->val, I think the code is clearer without this change. When > reading the function, seeing "val", I need to look up what it is, while > seeing "ctrl->val" gives me more context and makes (in my opinion) the > code more readable. Agreed, will revert to ctrl->val in v2. >> int sensor_gain; >> s64 max_expo; >> int ret; >> @@ -593,7 +595,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) >> switch (ctrl->id) { >> case V4L2_CID_VBLANK: >> /* Update max exposure while meeting expected vblanking */ >> - max_expo = ov4689->cur_mode->height + ctrl->val - 4; >> + max_expo = ov4689->cur_mode->height + val - 4; >> __v4l2_ctrl_modify_range(ov4689->exposure, >> ov4689->exposure->minimum, max_expo, >> ov4689->exposure->step, >> @@ -607,36 +609,34 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) >> switch (ctrl->id) { >> case V4L2_CID_EXPOSURE: >> /* 4 least significant bits of exposure are fractional part */ >> - ret = cci_write(ov4689->regmap, OV4689_REG_EXPOSURE, >> - ctrl->val << 4, NULL); >> + cci_write(regmap, OV4689_REG_EXPOSURE, val << 4, &ret); >> break; >> case V4L2_CID_ANALOGUE_GAIN: >> - ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain); >> + ret = ov4689_map_gain(ov4689, val, &sensor_gain); >> >> - cci_write(ov4689->regmap, OV4689_REG_GAIN_H, >> + cci_write(regmap, OV4689_REG_GAIN_H, >> (sensor_gain >> OV4689_GAIN_H_SHIFT) & >> OV4689_GAIN_H_MASK, &ret); >> >> - cci_write(ov4689->regmap, OV4689_REG_GAIN_L, >> + cci_write(regmap, OV4689_REG_GAIN_L, >> sensor_gain & OV4689_GAIN_L_MASK, >> &ret); >> break; >> case V4L2_CID_VBLANK: >> - ret = cci_write(ov4689->regmap, OV4689_REG_VTS, >> - ctrl->val + ov4689->cur_mode->height, NULL); >> + cci_write(regmap, OV4689_REG_VTS, >> + val + ov4689->cur_mode->height, &ret); >> break; >> case V4L2_CID_TEST_PATTERN: >> - ret = ov4689_enable_test_pattern(ov4689, ctrl->val); >> + ret = ov4689_enable_test_pattern(ov4689, val); >> break; >> default: >> dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", >> - __func__, ctrl->id, ctrl->val); >> + __func__, ctrl->id, val); >> ret = -EINVAL; >> break; >> } >> >> pm_runtime_put(dev); >> - >> return ret; >> } >> >> -- >> 2.43.0 >> -- Best regards, Mikhail Rudenko
diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 8c120d7f7830..42700ecfbe0e 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -584,7 +584,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) { struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); + struct regmap *regmap = ov4689->regmap; struct device *dev = ov4689->dev; + s32 val = ctrl->val; int sensor_gain; s64 max_expo; int ret; @@ -593,7 +595,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_VBLANK: /* Update max exposure while meeting expected vblanking */ - max_expo = ov4689->cur_mode->height + ctrl->val - 4; + max_expo = ov4689->cur_mode->height + val - 4; __v4l2_ctrl_modify_range(ov4689->exposure, ov4689->exposure->minimum, max_expo, ov4689->exposure->step, @@ -607,36 +609,34 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_EXPOSURE: /* 4 least significant bits of exposure are fractional part */ - ret = cci_write(ov4689->regmap, OV4689_REG_EXPOSURE, - ctrl->val << 4, NULL); + cci_write(regmap, OV4689_REG_EXPOSURE, val << 4, &ret); break; case V4L2_CID_ANALOGUE_GAIN: - ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain); + ret = ov4689_map_gain(ov4689, val, &sensor_gain); - cci_write(ov4689->regmap, OV4689_REG_GAIN_H, + cci_write(regmap, OV4689_REG_GAIN_H, (sensor_gain >> OV4689_GAIN_H_SHIFT) & OV4689_GAIN_H_MASK, &ret); - cci_write(ov4689->regmap, OV4689_REG_GAIN_L, + cci_write(regmap, OV4689_REG_GAIN_L, sensor_gain & OV4689_GAIN_L_MASK, &ret); break; case V4L2_CID_VBLANK: - ret = cci_write(ov4689->regmap, OV4689_REG_VTS, - ctrl->val + ov4689->cur_mode->height, NULL); + cci_write(regmap, OV4689_REG_VTS, + val + ov4689->cur_mode->height, &ret); break; case V4L2_CID_TEST_PATTERN: - ret = ov4689_enable_test_pattern(ov4689, ctrl->val); + ret = ov4689_enable_test_pattern(ov4689, val); break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", - __func__, ctrl->id, ctrl->val); + __func__, ctrl->id, val); ret = -EINVAL; break; } pm_runtime_put(dev); - return ret; }