From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D00A0C2BB54 for ; Tue, 7 Apr 2020 23:51:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AADFA20748 for ; Tue, 7 Apr 2020 23:51:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fikP9pwn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726578AbgDGXvD (ORCPT ); Tue, 7 Apr 2020 19:51:03 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42375 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726530AbgDGXvB (ORCPT ); Tue, 7 Apr 2020 19:51:01 -0400 Received: by mail-pl1-f194.google.com with SMTP id v2so461108plp.9 for ; Tue, 07 Apr 2020 16:50:59 -0700 (PDT) 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=WC7KT0pNRGqubghsLpqhU2AyP/TQtFiX3YW33bK8+tI=; b=fikP9pwnOKADqBxBp6Df8qFyXJbZ76/yDzRTxlPbEVuwcFBa9Ei7Jr/I/5rNnBOk15 9pdZBMzxFK3BfIz15xQFFhvyhaCBXDxtfrn0QjK8ffDM8t52m1JiTPdYSxR7Fh8CF45X aVVfCxai+xqCiTD5zYRJkfkB7ZtqR7kj3Emns= 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=WC7KT0pNRGqubghsLpqhU2AyP/TQtFiX3YW33bK8+tI=; b=D3YyMKlIVfa86MHxdY60GcGFO4Q/ufmkVO+IO/J1fZWN0Snu+bEeXLnixbAODlReuH 0/HKqVqLKf3I1AWHlu7N5uexL+g/RIqPvcFfX13eJU263VW9cZ43J6zXb0ObHBbTOe/G OHRMHOQBxeDnwfN6lJtcgC2OS6LZphLv0Df/PnU5gg5qK20nhVW1AJcPKj7CRQ/n+pR9 HORd8YXBEU/jBHN85h+TcZRuLCv/eXpOoTydboRGd1csUfsjLOvy3evYrPWcL3IjahHv 57+y+3ZHxL7EnWh2rc9tnJR9+FbGk3+sSx6cc3GB6/G+p3hRGBa0EV+X0AO4G8DjHJI3 bWfg== X-Gm-Message-State: AGi0PuZm+8MYoxn7CVw/bCm2+i3mQ9MpuGLM4TBUBwwlEkTZwfJdX4Et g184c9bT8jxG7l1JCxZ2SKOSeA== X-Google-Smtp-Source: APiQypIrWS1flrwcKiadKIyXre2kng3sWUWISf/o7P+SWHRdrX2RTHhTJrRyakO4f92FAblSxbF7xQ== X-Received: by 2002:a17:902:b183:: with SMTP id s3mr4638431plr.33.1586303459290; Tue, 07 Apr 2020 16:50:59 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id s27sm14467165pgn.90.2020.04.07.16.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 16:50:58 -0700 (PDT) From: Douglas Anderson To: Andy Gross , Bjorn Andersson , Maulik Shah Cc: mka@chromium.org, Lina Iyer , Rajendra Nayak , swboyd@chromium.org, evgreen@chromium.org, Douglas Anderson , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 03/10] drivers: qcom: rpmh-rsc: Fold tcs_ctrl_write() into its single caller Date: Tue, 7 Apr 2020 16:50:17 -0700 Message-Id: <20200407164915.v3.3.Ie88ce5ccfc0c6055903ccca5286ae28ed3b85ed3@changeid> X-Mailer: git-send-email 2.26.0.292.g33ef6b2f38-goog In-Reply-To: <20200407235024.260460-1-dianders@chromium.org> References: <20200407235024.260460-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 obvious (at least to me) their relationship. Simplify by folding one function into the other. Signed-off-by: Douglas Anderson Reviewed-by: Maulik Shah Tested-by: Maulik Shah --- Changes in v3: None Changes in v2: None 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 46455b1d93f1..e361b2331993 100644 --- a/drivers/soc/qcom/rpmh-rsc.c +++ b/drivers/soc/qcom/rpmh-rsc.c @@ -587,27 +587,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 * @@ -618,6 +597,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"); @@ -628,7 +612,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; } /** -- 2.26.0.292.g33ef6b2f38-goog