Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1268586lqd; Thu, 25 Apr 2024 10:14:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZnXNrWHN2VS+AGFAzdFE5A/R/NTk9pX0A0p6MLN1mXyZg+7Kk7AV8TrkORBJzYeBZDYuH8AsWfD+LXtqeVPmpL4p7fhW1Hjejd8VeLw== X-Google-Smtp-Source: AGHT+IHSOF2wQqoktmNt/2X8tglUKTECWHjsmae89MEWo63ZpRc5Iih1uy+2J7WAoX+PPpIftxLC X-Received: by 2002:a17:906:c04f:b0:a55:6b76:eedc with SMTP id bm15-20020a170906c04f00b00a556b76eedcmr292503ejb.14.1714065262222; Thu, 25 Apr 2024 10:14:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714065262; cv=pass; d=google.com; s=arc-20160816; b=CLPxWIm+cz+tZ+bL8LAPzVWF1hlh9QQPzuYACmyA6dupTphbD+4zwzdiotTn9hyIon pgIM4WTfqO499z1iGCTbqmAxDNLcIyoc2BhI9TvXBhjdPFyNN1X7pk1q9z9lnrGPib2N 7xEhsQHqn3n2hJyWFIABJ+ECHAOz2mXjiw/e40iJiyPTU1vgNZUZ2T0GxNCH35ItvJja Ls3cFFgCFO0AhNySeAwI3AtXLVfC8bWksylCjOzPeXH1ntBBlFEq+xYmtpgEu+Y/QJNI cgLkjV3NbXEppJ+VakBhhGKB1FcHmWc4BTvdf7cjibdcnf2I71XnKUoqhiirx1rOoQ5e YWyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=JVrgXdX8kamEaJvltEQAZzfNIWpOQgobLePARW6BHyw=; fh=q+OxTlnQ1YlHIMMs8NfAJfAGIFZk1Pi0F8iLh/irSPM=; b=J1RRWJrMgG3aMBmqXPcuiSf0+7ZBND9tLT+9QyC9/u99/v81jA/r9NNjgn5L8PSb+X sYbF+VfKD/j3QC4rFiQTOnwat16PFYe8hX0JFeSmyHVTZzxULVnHYjucscEYrh2lj85V zruFLiIS8ngj5uKcqYaSFx53HMz94fWM2IT+aXOFLpCulnhRPeF7lxjsUbpVQWs9QqHr nd5w/YdNhYfgAg4Zi6+FYllJdX0c/jddXfYXllLIF/hIH0CcrF0+aPJoHx0Lcwg4NgWC hMLGzU8klVzdrBWdhtlnDtwuUCAY1K0LyDwDdlb4IYZCS49hb+Lxc3GbE8HXcUEorsY9 fP8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=hacgZigG; arc=pass (i=1 spf=pass spfdomain=salutedevices.com dkim=pass dkdomain=salutedevices.com dmarc=pass fromdomain=salutedevices.com); spf=pass (google.com: domain of linux-kernel+bounces-158960-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158960-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=salutedevices.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v11-20020a170906180b00b00a46e28b5a79si9472136eje.818.2024.04.25.10.14.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 10:14:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158960-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=hacgZigG; arc=pass (i=1 spf=pass spfdomain=salutedevices.com dkim=pass dkdomain=salutedevices.com dmarc=pass fromdomain=salutedevices.com); spf=pass (google.com: domain of linux-kernel+bounces-158960-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158960-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=salutedevices.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C71BC1F25AB9 for ; Thu, 25 Apr 2024 17:14:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 512341514E7; Thu, 25 Apr 2024 17:13:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="hacgZigG" Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C59B14E2E7; Thu, 25 Apr 2024 17:13:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.89.224.132 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714065193; cv=none; b=Lm8iR/f+24nhn3gURbtKh1jHa1M2pXICRA0rRqfAUAeyaqQW9d9R02lbooS4uUjuB5uq6DlzHlphusiIUyD7hQfsJxM1A0lSY4S4DPzXzybH+m41Ung9NTKyzKmLvIPPedbSsbD3UT76OpUdEhwVBORsuEQq8vRhj4sGLzelsZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714065193; c=relaxed/simple; bh=lKHMkrDVVEE7R8BTBdZwOe8QEkELrApm+nqJkERY544=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jgXO3H+JdgqS1D46pBQLRAhh8fBSqHMwhYTPSO+hhuUlKJT5zCiGSM+6QCPZhUD5kwZPqDE1l4ULoHCVgwY+JbTg5srZJEQS25EoMbmYLNZppcFHbv+KqtnsSTCyEMwo31paqp7KugOh6cOQ7ItWoEj6DfYqU8ywao1uo/8f9vU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com; spf=pass smtp.mailfrom=salutedevices.com; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b=hacgZigG; arc=none smtp.client-ip=45.89.224.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=salutedevices.com Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 873B312000C; Thu, 25 Apr 2024 20:13:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 873B312000C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1714065181; bh=JVrgXdX8kamEaJvltEQAZzfNIWpOQgobLePARW6BHyw=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=hacgZigGhvKMoaRiuJ83hvQiZTCQVWAhgAxc1glqBPpO9++CICyrJuodgqWxYRKMT M7kMt3bWzI/3qPgbuycHhk/Kzl4IbaDc81tsTXfMoqhIqzl/h5LvpVA9h40mKLA3CI +pzXh1ik+29My4jDStWMcCTVoNIcLfd7B//NXoJSIjRWEv5kJard8cZkSAo8CYDkeF PnwBCSLp6H0NmDA4y58qosiEed6bzLRr8KmB/L1M0FEJ7ITYuQUDeYqYExcclKvJkp 4eqWJr7GxzgFbNxft8IoTZeVpz7S4TEGRhr7qli0bV10zyva2ylgBZSRn8lIn/lsBZ 8yBDx/Pl4IoPA== Received: from smtp.sberdevices.ru (p-i-exch-sc-m02.sberdevices.ru [172.16.192.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Thu, 25 Apr 2024 20:13:01 +0300 (MSK) Received: from work.sberdevices.ru (100.64.160.123) by p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 25 Apr 2024 20:13:00 +0300 From: George Stark To: , , , , , , CC: , , , , , George Stark , Dmitry Rokosov Subject: [PATCH v3 2/3] pwm: meson: Add check for error from clk_round_rate() Date: Thu, 25 Apr 2024 20:12:52 +0300 Message-ID: <20240425171253.2752877-3-gnstark@salutedevices.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240425171253.2752877-1-gnstark@salutedevices.com> References: <20240425171253.2752877-1-gnstark@salutedevices.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) To p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 184930 [Apr 25 2024] X-KSMG-AntiSpam-Version: 6.1.0.4 X-KSMG-AntiSpam-Envelope-From: gnstark@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 18 0.3.18 b9d6ada76958f07c6a68617a7ac8df800bc4166c, {Tracking_from_domain_doesnt_match_to}, 100.64.160.123:7.1.2;smtp.sberdevices.ru:7.1.1,5.0.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;127.0.0.199:7.1.2, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2024/04/25 14:02:00 #24969020 X-KSMG-AntiVirus-Status: Clean, skipped clk_round_rate() can return not only zero if requested frequency can not be provided but also negative error code so add check for it too. Also change type of variable holding clk_round_rate() result from unsigned long to long. It's safe due to clk_round_rate() returns long. Fixes: 329db102a26d ("pwm: meson: make full use of common clock framework") Signed-off-by: Dmitry Rokosov Signed-off-by: George Stark --- drivers/pwm/pwm-meson.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index f4d70da621ec..4a652d500dfc 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -148,7 +148,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, struct meson_pwm *meson = to_meson_pwm(chip); struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm]; unsigned int cnt, duty_cnt; - unsigned long fin_freq; + long fin_freq; u64 duty, period, freq; duty = state->duty_cycle; @@ -168,12 +168,13 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, freq = ULONG_MAX; fin_freq = clk_round_rate(channel->clk, freq); - if (fin_freq == 0) { - dev_err(pwmchip_parent(chip), "invalid source clock frequency\n"); - return -EINVAL; + if (fin_freq <= 0) { + dev_err(pwmchip_parent(chip), + "invalid source clock frequency %llu\n", freq); + return fin_freq ? fin_freq : -EINVAL; } - dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq); + dev_dbg(pwmchip_parent(chip), "fin_freq: %ld Hz\n", fin_freq); cnt = div_u64(fin_freq * period, NSEC_PER_SEC); if (cnt > 0xffff) { -- 2.25.1