From patchwork Sun Aug 18 14:23:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thorsten Blum X-Patchwork-Id: 13767453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F37C6C52D7C for ; Sun, 18 Aug 2024 14:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=84N+5XgwWf1nwoq814fYSNnKDtDJw7Qd1tBkSaBztTo=; b=ZdggQIp47NVbG+VJ/n6m6EpS2f fVZo8tqvzSI9gTC082MjgpUzCYhu2sWwa9TI5VwQfA0DcHBEvwgZLEDqQfHptaTL43M1ORTQTZsNY iqjCOCnuqlwc2wJTuemzyxbrQGWibsEDKOnGlC+t8VkY0n3ZLjIOjfIGUrd9JvC4JgWZ4tQxJgmsB 1NEeDHC9COxYf8/0n9SNACMJZ0jyfQLpwoH/FCDawwqE6iFPmrsZtg7w/wG+at14TW81fo94d8F4T djFIgU3SpYY69Bns8dxr1HtJCKprDd1gR8N3Pr2/vOmgMNgiZsiMnlOJjGDVOKMcwzK8f7+Xk2cde zY6am3kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfgpi-0000000Ggye-1xPH; Sun, 18 Aug 2024 14:24:39 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sfgp0-0000000Ggp4-0Vvv for linux-arm-kernel@lists.infradead.org; Sun, 18 Aug 2024 14:23:55 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a7aa212c1c9so402178866b.2 for ; Sun, 18 Aug 2024 07:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toblux-com.20230601.gappssmtp.com; s=20230601; t=1723991032; x=1724595832; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=84N+5XgwWf1nwoq814fYSNnKDtDJw7Qd1tBkSaBztTo=; b=TZIkX7te292Zt+RxFvqXgsa4L1HouyjNn+ypfx6/mmQX597PB4u4xmDsBTKzF5e4vx I/MA0tKUeGsCWQ+cnVtVZq79N2AJJF2t4PA6nuDhY6eIwY1jpEA+zmf0aB9qDx4IycoN 4rMV03/rLCNOHeb5gpRIwdjW38k5hGXEZXazkHgXpDv7j73MkwppzqxEvxA/gDDKqH4r MSYwxzza0Jmgyz314UFGr94HXlEDGNRoKrV/Gunqg8nSHP6cexATSId90Wj4ytWaleBk y87Kqx4nZs2o/Ze4kXdDF0/bc9UIWOX6rPqR65ffp5H7OCvu49Gw9EPmrFCJhOSCJ3mQ KTmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723991032; x=1724595832; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=84N+5XgwWf1nwoq814fYSNnKDtDJw7Qd1tBkSaBztTo=; b=lNOUx2azvHoyr6+kuGzDzcJIsZUCzQdiqmWjkvIoDNs+xvJCexl2Lhl6DDRgLvp4sx /e7cv/s539j1DnFuot6S6kazkZvnSJckTjOYwc97esuOuIyuw3Te3JjkY6Z+VAz+bh3y FhZPwtJFDZ4S4s5ER/Vg8t8+aBjv6s65csbKgTp/EMHwzQLgMFx3J1GzpMkqcDcMtfV+ tTWH4ChpZlyDjcVt7Col8wa/zZQbmz00Po2vyg96Yphrt58JHl51OWeyU+apb+m/pYPb BctFnIomMyXBg4MO/21h8NIJW00KplHBoI97/1URffd6tPAO2seXrzCrOueBWNotD4AC pY4w== X-Forwarded-Encrypted: i=1; AJvYcCX66PQ/wjGIsdBGrbte0qbLeSw0eoyO03zEoWvtb/gwxL6CK49c2gVinykHxR/h2azJBSs95xCYRCGuh0Gy7zhUfhjqksZksf/NRDnq7eKsrNlPfwo= X-Gm-Message-State: AOJu0Yy6duZfxuM+JkHrJjMxkwz9YGQ77KF2xaR/7Mq3EPeoQ4M+iqhx 7fJl+iPI3dPReABcg3C+WREPbLdw2uNgYE6kkzXYn8igSQegzwlST9qWDqCAZJ0= X-Google-Smtp-Source: AGHT+IGf2pCDxIA75jH/7/L+NTnSfTLwTcnLAynOVUmTnc/INCAsrC+TWCaYgIwOf2GFYNoBXz2Lfw== X-Received: by 2002:a17:907:f1dc:b0:a7a:a89e:e230 with SMTP id a640c23a62f3a-a839295469fmr583647666b.30.1723991032263; Sun, 18 Aug 2024 07:23:52 -0700 (PDT) Received: from fedora.fritz.box (aftr-62-216-208-163.dynamic.mnet-online.de. [62.216.208.163]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a83838d023dsm519702566b.64.2024.08.18.07.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 07:23:51 -0700 (PDT) From: Thorsten Blum To: chaotian.jing@mediatek.com, ulf.hansson@linaro.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Thorsten Blum Subject: [PATCH v3] mmc: mtk-sd: Improve data type in msdc_timeout_cal() Date: Sun, 18 Aug 2024 16:23:01 +0200 Message-ID: <20240818142300.64156-2-thorsten.blum@toblux.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240818_072354_187612_E5C6923B X-CRM114-Status: GOOD ( 14.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The local variable clk_ns uses at most 32 bits and can be a u32. Replace the 64-by-32 do_div() division with a standard divison. Since do_div() casts the divisor to u32 anyway, changing the data type of clk_ns to u32 also removes the following Coccinelle/coccicheck warning reported by do_div.cocci: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead Use min_t(u32,,) to simplify the code and improve its readability. Signed-off-by: Thorsten Blum --- Changes in v2: - Address kernel test robot feedback and replace do_div() with a standard division - Link to v1: https://lore.kernel.org/linux-kernel/20240815234602.59684-1-thorsten.blum@toblux.com/ Changes in v3: - Use min_t() instead of max_t() - Link to v2: https://lore.kernel.org/linux-kernel/20240817170726.350339-2-thorsten.blum@toblux.com/ --- drivers/mmc/host/mtk-sd.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c index a94835b8ab93..edeab9a4a83b 100644 --- a/drivers/mmc/host/mtk-sd.c +++ b/drivers/mmc/host/mtk-sd.c @@ -795,14 +795,13 @@ static void msdc_unprepare_data(struct msdc_host *host, struct mmc_data *data) static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks) { struct mmc_host *mmc = mmc_from_priv(host); - u64 timeout, clk_ns; - u32 mode = 0; + u64 timeout; + u32 clk_ns, mode = 0; if (mmc->actual_clock == 0) { timeout = 0; } else { - clk_ns = 1000000000ULL; - do_div(clk_ns, mmc->actual_clock); + clk_ns = 1000000000U / mmc->actual_clock; timeout = ns + clk_ns - 1; do_div(timeout, clk_ns); timeout += clks; @@ -831,7 +830,7 @@ static void msdc_set_timeout(struct msdc_host *host, u64 ns, u64 clks) timeout = msdc_timeout_cal(host, ns, clks); sdr_set_field(host->base + SDC_CFG, SDC_CFG_DTOC, - (u32)(timeout > 255 ? 255 : timeout)); + min_t(u32, timeout, 255)); } static void msdc_set_busy_timeout(struct msdc_host *host, u64 ns, u64 clks) @@ -840,7 +839,7 @@ static void msdc_set_busy_timeout(struct msdc_host *host, u64 ns, u64 clks) timeout = msdc_timeout_cal(host, ns, clks); sdr_set_field(host->base + SDC_CFG, SDC_CFG_WRDTOC, - (u32)(timeout > 8191 ? 8191 : timeout)); + min_t(u32, timeout, 8191)); } static void msdc_gate_clock(struct msdc_host *host)