Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp60002ybh; Fri, 6 Mar 2020 16:00:57 -0800 (PST) X-Google-Smtp-Source: ADFU+vvF2hS7JBaALb0xCwRD7yaVZceLmYs2xCc1oTdwGXCSYtcL22EJem6EmdoUMvW/1A0AgdrW X-Received: by 2002:aca:d954:: with SMTP id q81mr4455162oig.157.1583539257764; Fri, 06 Mar 2020 16:00:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583539257; cv=none; d=google.com; s=arc-20160816; b=aao8yYRMNn85N81AMMKAKrGHdDXTpwYxJYh3a4VeiO97OrTgoW3Uz+pZ2FTY1P3Rb0 qMXLBGfs20QwEfZC7831iVFHiUGgDhVkbeEP6t9Jw09IOy/8+TK6JquPDxnOihoXKS9R noUjzQjVHXbnjFACt7eCP5jRlSoSZKviQs+HuxYF9A+m8IiSx9L4ioacQz3/w0p9PxPX lbA46CqQ0XOdReeawRumITdP8LlTOpPKzoz4yvNi2J7PwP36clHOGq1ncJd21hBfymD2 Mw3YP9mIkKMZk3lNUyCJ0yaYLxmb2Ijg3jLveVhiaQFn7ytZUTbpB5lWv+CI7SjlL0Mv 6+9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PUD2Oo1s4utNAJVcpGMDyjbipm4gk6JktG+dqhBf1yA=; b=k+TdA6VUhPeJXvEgBeJvTuQzfA9qXS6F1K1NxpVFMGrnnIZucNUBHi334V08xgHcbn 7eH8Ybwljb6jtBCAvhf64gL8xQVdpRkJMvbaCaOlBj8m9g/4Vi58sh6dWtTpGiy6fB5+ lHi8PgR7Zx9IcciakNAJtSrWc/eLNISJHmCc8u3aGV0MA+SIA9NA9EeNEllqlX2SJBVl LVSk9QyH55BZKNDimU+QN3DrPHCnbYkbrSgt2ifSdPSNRvVG6eMjrXmlRt4sNxihE1wT gbVthjJDsbZZu2bsSPSoFLK2YJkvUN6IY7ajQDtcEYr7jShH7PGLCuObJtvDfaiR7znH KSoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OivIinsR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si2264514otj.321.2020.03.06.16.00.46; Fri, 06 Mar 2020 16:00:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OivIinsR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726898AbgCGAA0 (ORCPT + 99 others); Fri, 6 Mar 2020 19:00:26 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36247 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbgCGAAZ (ORCPT ); Fri, 6 Mar 2020 19:00:25 -0500 Received: by mail-pg1-f196.google.com with SMTP id d9so1808089pgu.3 for ; Fri, 06 Mar 2020 16:00:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PUD2Oo1s4utNAJVcpGMDyjbipm4gk6JktG+dqhBf1yA=; b=OivIinsRd3lHnnY/HAsTFzA+ojvtyfBR3w8fMpEsjluPTvLTS1CgE7fKU7kfZKaJEa xw/ldsn6XU6/dmcY3Tv35D7peKe87zhkbIXTYePvVIsJWT8IiKsL7pqhsbCH+ACEum1i 91BdekCfKUzQdE6j1iSXbVarvGv2I/SQ7SMTY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PUD2Oo1s4utNAJVcpGMDyjbipm4gk6JktG+dqhBf1yA=; b=aO6Ud/zD1HK/LlbPD+9636agKaOmHsxfZzm01dCb+0zAIDVgntYqsuFSyktlQi6P9i Jmq6SiiDK3JqJq8PlPx25omrFEqmZC1rms+9bwLqv1f02c5tESB1Y7r6ByGLn6JHiMrg TyANWLx/4Zk9Xdws+C1FcR0Kf+UCv9FukotdkfnrL3tvYJrWPn7yPmubEq+j5Eceux4c J0zSHPqzQuj21WoYSyQCEaLWBq6tvmGtMffUXKzXX5ONYYGKC5BLyFTqo2hTPN4LXj9c /K+TzJ7D9r+YNRcjraDUVazcc0fcLXfLHfP5X8mdCBWGR0Ixrj55QlEcLCbZzd0498Vs GZHg== X-Gm-Message-State: ANhLgQ11W/jL2uoZMfQYpK0e9uEZPTswoZJtMiu3hqOOZueE8Z2TnnQj D2whMRCmI+yYRIkispLVj10exQ== X-Received: by 2002:a63:564d:: with SMTP id g13mr5447188pgm.157.1583539224333; Fri, 06 Mar 2020 16:00:24 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id 9sm32302246pge.65.2020.03.06.16.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 16:00:23 -0800 (PST) From: Douglas Anderson To: Andy Gross , Bjorn Andersson , Maulik Shah Cc: Rajendra Nayak , mka@chromium.org, evgreen@chromium.org, swboyd@chromium.org, Lina Iyer , Douglas Anderson , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFT PATCH 3/9] drivers: qcom: rpmh-rsc: Fold tcs_ctrl_write() into its single caller Date: Fri, 6 Mar 2020 15:59:45 -0800 Message-Id: <20200306155707.RFT.3.Ie88ce5ccfc0c6055903ccca5286ae28ed3b85ed3@changeid> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200306235951.214678-1-dianders@chromium.org> References: <20200306235951.214678-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I was trying to write documentation for the functions in rpmh-rsc and I got to tcs_ctrl_write(). The documentation for the function would have been: "This is the core of rpmh_rsc_write_ctrl_data(); all the caller does is error-check and then call this". Having the error checks in a separate function doesn't help for anything since: - There are no other callers that need to bypass the error checks. - It's less documenting. When I read tcs_ctrl_write() I kept wondering if I need to handle cases other than ACTIVE_ONLY or cases with more commands than could fit in a TCS. This is obvious when the error checks and code are together. - The function just isn't that long, so there's no problem understanding the combined function. Things were even more confusing because the two functions names didn't make it obvious (at least to me) their relationship. Simplify by folding one function into the other. Signed-off-by: Douglas Anderson --- drivers/soc/qcom/rpmh-rsc.c | 39 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c index 0a409988d103..099603bf14bf 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -549,27 +549,6 @@ static int find_slots(struct tcs_group *tcs, const struct tcs_request *msg, return 0; } -static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg) -{ - struct tcs_group *tcs; - int tcs_id = 0, cmd_id = 0; - unsigned long flags; - int ret; - - tcs = get_tcs_for_msg(drv, msg); - if (IS_ERR(tcs)) - return PTR_ERR(tcs); - - spin_lock_irqsave(&tcs->lock, flags); - /* find the TCS id and the command in the TCS to write to */ - ret = find_slots(tcs, msg, &tcs_id, &cmd_id); - if (!ret) - __tcs_buffer_write(drv, tcs_id, cmd_id, msg); - spin_unlock_irqrestore(&tcs->lock, flags); - - return ret; -} - /** * rpmh_rsc_write_ctrl_data: Write request to the controller * @@ -580,6 +559,11 @@ static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg) */ int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, const struct tcs_request *msg) { + struct tcs_group *tcs; + int tcs_id = 0, cmd_id = 0; + unsigned long flags; + int ret; + if (!msg || !msg->cmds || !msg->num_cmds || msg->num_cmds > MAX_RPMH_PAYLOAD) { pr_err("Payload error\n"); @@ -590,7 +574,18 @@ int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, const struct tcs_request *msg) if (msg->state == RPMH_ACTIVE_ONLY_STATE) return -EINVAL; - return tcs_ctrl_write(drv, msg); + tcs = get_tcs_for_msg(drv, msg); + if (IS_ERR(tcs)) + return PTR_ERR(tcs); + + spin_lock_irqsave(&tcs->lock, flags); + /* find the TCS id and the command in the TCS to write to */ + ret = find_slots(tcs, msg, &tcs_id, &cmd_id); + if (!ret) + __tcs_buffer_write(drv, tcs_id, cmd_id, msg); + spin_unlock_irqrestore(&tcs->lock, flags); + + return ret; } static int rpmh_probe_tcs_config(struct platform_device *pdev, -- 2.25.1.481.gfbce0eb801-goog