From patchwork Tue Dec 4 16:34:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 152821 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8267178ljp; Tue, 4 Dec 2018 08:34:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/WwVNqbuGVlOQMhmIkEvPQ0kzG9WkGmHDuv6co54tKnV4Qe3gmhuZVoNUmuwEKxZ2Qk+zM1 X-Received: by 2002:a65:4784:: with SMTP id e4mr16877855pgs.12.1543941255548; Tue, 04 Dec 2018 08:34:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543941255; cv=none; d=google.com; s=arc-20160816; b=R+P7SZ41qabrHRsmfGlWutqWbvlgF0AU5vPH14AaiYDraLbHJCPhp7NxkS/i5ABRLD z200m7KF8VcFYlSC6ugPeRTmNItJTHIAzl+fL9B7p2PCYyOTzP0+alKwBD2vDDlkG4CP F/qJ/IZc95h/cwbBeSrE22UTycwsV+JxMcFWCmPJILkCNwMsGrLmk96kSbqY9yPFQJ/8 wyqxiOxHW1acIf0EK9L9v8cpkkslhbfvwXu3NXWC8Kuj14/3kAofH9oBfEOzA26hqncN BzINOGG6GInO5kJ6ygc8SIvNNGoFw0Aw8Ua0cjtbq1Eve8fxwFVjLpQ6vQbJvUTeWyiU 6ZMw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KPLi5PSQm0wZ5w0jVFRD2zaX5ehve+yaUgJvEMdE2d8=; b=zDydZ67LWvD2oH2+jnC43h7hlbnua20SPeLiaD8xDDTz13rfYI8Ypq47jeMOBv9ZeB 3XXVheMAZSSX7H5+H/REEsR+vR5jSfF940wzxuq8HOFJmXt+0Dtv72oZiG6RMMaON6yD noqVPT4RyWZNS4w8wAYaAi/tnw+XeryC1wyB0++JGoE6FiLVNbDY5FZkw2N+POGBq/sa T99pPCXsxuPpphmYZVbBlqI50gGyKRkg/YQK+ixP3OKTJQyBt2R6xyRuXZXvFkV7IFSy iaEMUTY21Esq6oCb8nxSu2b0Q6xOvMM1r+Zu/qSmgDbShvcxEl2Hrget8oi25MOevNuU hwmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=bZlFbFs+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v30si13850212pga.45.2018.12.04.08.34.15; Tue, 04 Dec 2018 08:34:15 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=bZlFbFs+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727036AbeLDQeN (ORCPT + 31 others); Tue, 4 Dec 2018 11:34:13 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50880 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726367AbeLDQeN (ORCPT ); Tue, 4 Dec 2018 11:34:13 -0500 Received: by mail-wm1-f68.google.com with SMTP id n190so7851451wmd.0 for ; Tue, 04 Dec 2018 08:34:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KPLi5PSQm0wZ5w0jVFRD2zaX5ehve+yaUgJvEMdE2d8=; b=bZlFbFs+lIC+cfNlxMCjI9WMSWaT72J+TKgmmJlm6NUjYdIeUe00UM++FjLTw1ioYc sPkvvNKNATgwinQ3gf91BCzEpnjqhVDgyj6+XLD2BjRszO4HzigEi1KovmbLcs5bNGN+ sFwlYVhny0ncAeNdCc11Wf3y/gTgVrhiHC+YNuZsDL9iz7IAgPcaAoo7c2zQX77t/pxG LUTL1aY8nP9i3cBIcXcrV7Y9Ao+N+Ds12QyVZJ50CexL8ZEfrWDVj6t1Wy7cCBOZEXdO nWxZN/kSd59W0/++GD7mXjUtkXsfdZfRMZBTQGWNBSJH73EASNmYwBSnZqmFAobQyzO1 K7IQ== 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=KPLi5PSQm0wZ5w0jVFRD2zaX5ehve+yaUgJvEMdE2d8=; b=TcyHRLrqmTKEKboiZ8TsGohrQHsNpzki4D6ME4jqNHxzQ9Zd1fird+N7INFeZeodjV l6RPt8250ncDwPf/fLxv9kaKfjGxG9SirOzPuntKUHwC+b5RVJ24p8g9AyHv+sxlRQnT Rus/r5AYnGaRzzzBw8B17g6FovjGYM9dDjgeCGsrye9MOCcuNdAOxv4aLlJM3iPr0Top bSlCWl20TUK5flh5Y18oXMmFz+Ppt90zxadeXQKm+/Pnc+sk2H9oi2vvdi1ilQYNGwnE KmM57CCKYdH+aOJO2P9cGISyjAAtMuhyVjMd34aG9osC3VfUY6YBky5yFfYPbxzeaKJA VI0g== X-Gm-Message-State: AA+aEWarTSQIAeCw2eAdEQGQzQH9kERegHoqVABwQam9U3paisFfmzPt VslIaHwtjRNu7viO+E2q4V6OKg== X-Received: by 2002:a1c:3489:: with SMTP id b131mr12768188wma.44.1543941250775; Tue, 04 Dec 2018 08:34:10 -0800 (PST) Received: from boomer.local ([2a01:e34:eeb6:4690:106b:bae3:31ed:7561]) by smtp.googlemail.com with ESMTPSA id t76sm22174826wme.33.2018.12.04.08.34.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 08:34:10 -0800 (PST) From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: Jerome Brunet , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: fix clk_mux_val_to_index() error value Date: Tue, 4 Dec 2018 17:34:03 +0100 Message-Id: <20181204163403.32321-1-jbrunet@baylibre.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org clk_mux_val_to_index() is meant to be used by .get_parent(), which returns a u8, so when the value provided does not map to any valid index, it is not a good idea to return a negative error value. Instead, return num_parents which we know is an invalid index and let CCF deal with it. Fixes: 77deb66d262f ("clk: mux: add helper function for index/value translation") Signed-off-by: Jerome Brunet --- drivers/clk/clk-mux.c | 8 ++++---- include/linux/clk-provider.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) -- 2.19.1 diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c index 1628b93655ed..b64e475802cc 100644 --- a/drivers/clk/clk-mux.c +++ b/drivers/clk/clk-mux.c @@ -26,8 +26,8 @@ * parent - parent is adjustable through clk_set_parent */ -int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags, - unsigned int val) +u8 clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags, + unsigned int val) { int num_parents = clk_hw_get_num_parents(hw); @@ -37,7 +37,7 @@ int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags, for (i = 0; i < num_parents; i++) if (table[i] == val) return i; - return -EINVAL; + return num_parents; } if (val && (flags & CLK_MUX_INDEX_BIT)) @@ -47,7 +47,7 @@ int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags, val--; if (val >= num_parents) - return -EINVAL; + return num_parents; return val; } diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 60c51871b04b..fc20886ef069 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -550,8 +550,8 @@ struct clk_hw *clk_hw_register_mux_table(struct device *dev, const char *name, void __iomem *reg, u8 shift, u32 mask, u8 clk_mux_flags, u32 *table, spinlock_t *lock); -int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags, - unsigned int val); +u8 clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags, + unsigned int val); unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index); void clk_unregister_mux(struct clk *clk);