Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp609158pxk; Wed, 2 Sep 2020 10:00:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNr3FdXsM4au9Wkm2E3lLGgpXz4rFi28QgupFYwfH8GRT+O+S+nf7fl83QM+I/cKUNn3NB X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr1010246edr.11.1599066005932; Wed, 02 Sep 2020 10:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599066005; cv=none; d=google.com; s=arc-20160816; b=iYmIcKyovuT+VrqQhjWR4t1PuKdpEqitJU9dSAo1hEgVfcbl+ZceWOtX7RElMHSjSu arKAhTcSYMA5rAL0WdoN28WoK0fkxtGAQ21tSjQDh9HW3hO9kw0gEDb0XOk7PRUUGY3E Bv/RqTCujLVrz6Rx4ER4BFJ8+Ru4Aesid6g2PVPY+9I/sDhs/mABAlsDAk/rlDQfOqNh LEtRWFsVcMS6UHJk1neFHN+Esy4qUNhjjFcwlfeXAcAoAUeGsEHRCRIM7vBnfRSpemjM sj2abGGcCDdQXisNI6++e14XhRAjHTEJr2smPfo4HigYgT5nqm3+X0IgPgumKOYpi1oh QXlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=JcXQvmAkY/k2J1p9we4yfCScXrpnX5eBNUZhNJtw/Hk=; b=xb4/D1IAwIBYnST/p1BRyfL4AsvG1/6kVv5JP7foRboCzxEl1l9GQtuEvnjKSLmlKf mC/Fnp0b8NL8Y0xjregy3yg/iNFrDvrd/7xXAAAWC9aYrtBSEzjRyc9lyxSfAclqo8+O YBK/FZWFQBpLuoNl8y9/weB0e+flPGlUR19e9UD+S9RyGmdsbW8mMTQbDS1FuOsCDpQO x8+Dxs5HzTL21Rx+E5wvFHKrxD5u4hLYHwdNDnHaoMM6rn7HLD9kt9s3Mx63VjI0pfLF WwdUhR/ky8OoyIoeWKo7AlVRxsPNAdtWDy6MDtVrSss71U2MFTPrTkfsW1y+t4oDKDSh aEkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jaDoR8zH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t22si66896ejy.466.2020.09.02.09.59.42; Wed, 02 Sep 2020 10:00:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jaDoR8zH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728386AbgIBQ6b (ORCPT + 99 others); Wed, 2 Sep 2020 12:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727026AbgIBQ6X (ORCPT ); Wed, 2 Sep 2020 12:58:23 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 464A4C061244; Wed, 2 Sep 2020 09:58:22 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id z1so178144wrt.3; Wed, 02 Sep 2020 09:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JcXQvmAkY/k2J1p9we4yfCScXrpnX5eBNUZhNJtw/Hk=; b=jaDoR8zHGWv18DZ+k2xRN07EgfAnZ+2OtQTUEsDgS2Nvtiwv4dbl7FdLnw+v8ogXKP IMQQbEAkaVY21jp4yPHkzkdnmeSKvw2i7L+6m+oITeHfBtrLGKyWUByU2JIh7fgnkQbp bbg99vBEaeAYHE0xgr/9QZi1zx5d+2cnSbNhKc+IA804dttxHFV2YRdv5EMjr9DoY/qb Yi2lVRfBCAutj3gUwyx5hQY+957XlH6H+Zix/qZuAs6QtD/SpLwRYbLNCFgmjk0N9QTw 0o4y6hpEJ1zIl7Wfl09nMZpS0hLGJ5Ae+VOfnr4xFTvFEz6ispXooDBEzykBeCcR9384 cDfg== 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:mime-version :content-transfer-encoding; bh=JcXQvmAkY/k2J1p9we4yfCScXrpnX5eBNUZhNJtw/Hk=; b=KIZV47ZKQNePAhyQYW/F2G5xTRqjhwLmaryX/4jZXR+n/gfbPURF/37lKU0Eeyk7lg j15do3nLMTcAQTjcavoq/uYUIUzOdGcPkohj4bVqG6H+5lcS76fNSfSSq3/IF6rlkbvW ybguXjZjaTVgeCj9hda8VvGGYyWK5qIlK/b000m9xyWh2iX7GQLTSiJkRO437n3Jlgry WCFLRY+emba9WOoaE8SDGtcEawxz+eXPkTKxwhoEJNaPckSlqU+sM1myGDpSPDJb4gYS MaIlDJ4zMPA5qcklBWNw8LY6r+LEF/ml7viw+EK6VF/AYQjfhP4IsPmyMfjQKYp1Fmqf YNqQ== X-Gm-Message-State: AOAM532XNCBO1o6fSVWTDpeR0TVR2wo80wPnb/xUVVn54quWOwxJejYK 4TCXEAGY2zTeV8aj+6FR24g= X-Received: by 2002:a5d:4e0b:: with SMTP id p11mr7711127wrt.13.1599065900919; Wed, 02 Sep 2020 09:58:20 -0700 (PDT) Received: from localhost.localdomain (cpc83661-brig20-2-0-cust443.3-3.cable.virginm.net. [82.28.105.188]) by smtp.gmail.com with ESMTPSA id c205sm369795wmd.33.2020.09.02.09.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 09:58:20 -0700 (PDT) From: Alex Dewar Cc: Alex Dewar , Sebastian Reichel , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] power: supply: charger-manager: Tidy function Date: Wed, 2 Sep 2020 17:58:16 +0100 Message-Id: <20200902165816.401213-1-alex.dewar90@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org check_charging_duration() contains some copy-pasted code, which makes it less readable. Refactor the function to be a bit tidier. I've also fixed a couple of typos. Signed-off-by: Alex Dewar --- drivers/power/supply/charger-manager.c | 39 +++++++++----------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c index 07992821e252..67c7b1fb6601 100644 --- a/drivers/power/supply/charger-manager.c +++ b/drivers/power/supply/charger-manager.c @@ -443,42 +443,31 @@ static int try_charger_enable(struct charger_manager *cm, bool enable) * check_charging_duration - Monitor charging/discharging duration * @cm: the Charger Manager representing the battery. * - * If whole charging duration exceed 'charging_max_duration_ms', + * If whole charging duration exceeds 'charging_max_duration_ms', * cm stop charging to prevent overcharge/overheat. If discharging - * duration exceed 'discharging _max_duration_ms', charger cable is + * duration exceeds 'discharging _max_duration_ms', charger cable is * attached, after full-batt, cm start charging to maintain fully * charged state for battery. */ static int check_charging_duration(struct charger_manager *cm) { struct charger_desc *desc = cm->desc; - u64 curr = ktime_to_ms(ktime_get()); u64 duration; - int ret = false; - if (!desc->charging_max_duration_ms && - !desc->discharging_max_duration_ms) - return ret; - - if (cm->charger_enabled) { - duration = curr - cm->charging_start_time; - - if (duration > desc->charging_max_duration_ms) { - dev_info(cm->dev, "Charging duration exceed %ums\n", - desc->charging_max_duration_ms); - ret = true; - } - } else if (cm->battery_status == POWER_SUPPLY_STATUS_NOT_CHARGING) { - duration = curr - cm->charging_end_time; + if ((desc->charging_max_duration_ms == 0 && + desc->discharging_max_duration_ms == 0)) + return false; + if (!cm->charger_enabled && + cm->battery_status != POWER_SUPPLY_STATUS_NOT_CHARGING) + return false; - if (duration > desc->charging_max_duration_ms) { - dev_info(cm->dev, "Discharging duration exceed %ums\n", - desc->discharging_max_duration_ms); - ret = true; - } + duration = ktime_to_ms(ktime_get()) - cm->charging_start_time; + if (duration > desc->charging_max_duration_ms) { + dev_info(cm->dev, "Charging duration exceeds %ums\n", + desc->charging_max_duration_ms); + return true; } - - return ret; + return false; } static int cm_get_battery_temperature_by_psy(struct charger_manager *cm, -- 2.28.0