From patchwork Sat Jul 8 07:27:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Kresin X-Patchwork-Id: 9831383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55060602A0 for ; Sat, 8 Jul 2017 07:27:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CF2B2852B for ; Sat, 8 Jul 2017 07:27:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 319672853D; Sat, 8 Jul 2017 07:27:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5090B2852B for ; Sat, 8 Jul 2017 07:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752715AbdGHH1w (ORCPT ); Sat, 8 Jul 2017 03:27:52 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:36771 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751078AbdGHH1v (ORCPT ); Sat, 8 Jul 2017 03:27:51 -0400 Received: by mail-wr0-f194.google.com with SMTP id 77so12225290wrb.3 for ; Sat, 08 Jul 2017 00:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kresin-me.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=LOuMPyTvVzNjX4+xm+imzT9BLAayj3Wz8dEkVNRQLPw=; b=wx60cYon0d7okW3MOXnoTULXjkC9Q05osK3xcbpF3vVRuv0WYZvUHs0c+9T+VCKvQT Upqb8L0M3G+yQHjBGCzz9sZM5VeXPm4U6S9CSw1+JClQZEtSKR8eg2QKbH73MgwKpsGF E42WTePrursHoQ27zWS03uuTOMfL+Y1tN6B7EvBG67ejjARNPlQtyVmfXcN138drcacv 24j5XKbg3ngr8Ht0nNKXD7Yv3Yug9xvBWAM9+0FkgGN/49qKjeEmRtAY6iaZe2yL7qJE o0dD6uPcjn7BMFpPcq5cFcOeEK4mavrd6PsAjxKRWUXnPfGdJmDIO6GBgddNJ8ky31+x WjaA== 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; bh=LOuMPyTvVzNjX4+xm+imzT9BLAayj3Wz8dEkVNRQLPw=; b=m45p8brkIsoIzihuGRIxLsUEz/0Iz+X5bUbBoYgFvX6IU7inKjfOMGFO3us1cgQ863 GXa5b1sfQDhVCTQ4Slyw2J4w+F3SG5QPoU2Q9jIyey7Rku+j5na5A2LndB0q3eXVgJek wYJkMlfWf1laXIkT2t3nfxARtWFKM+VuVNVWttNlal0xR8mEHsJ4gpBsGl/PS0JWfHBK W+68jdsVwMV/WeUr6JB9SyQvid2DQisb0kSiB3BEWCCmJegJ3QdPoNT1XxW6E7kAfLe0 bjVNmz7wbwcwNWu+oy71lQG0tKHX1fjeHm7CR6ibUd2MDQStffFwH5ZeINhDcOwnH40z UsmA== X-Gm-Message-State: AIVw112fDxOaPxjZJzEz0ZebnaQeyNM7lYYidJZGZVGnNJJg5cNQ3Drk Nak7lrAsKE+kGKXG X-Received: by 10.28.215.145 with SMTP id o139mr1484273wmg.5.1499498870255; Sat, 08 Jul 2017 00:27:50 -0700 (PDT) Received: from desktop.wvd.kresin.me (p2003008C2F4D320011E39C9060AC7945.dip0.t-ipconnect.de. [2003:8c:2f4d:3200:11e3:9c90:60ac:7945]) by smtp.gmail.com with ESMTPSA id j31sm2531923wre.67.2017.07.08.00.27.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 08 Jul 2017 00:27:49 -0700 (PDT) From: Mathias Kresin To: sgruszka@redhat.com, helmut.schaa@googlemail.com, kvalo@codeaurora.org Cc: linux-wireless@vger.kernel.org Subject: [PATCH] rt2x00: call clk_get_rate only if we have a clock Date: Sat, 8 Jul 2017 09:27:43 +0200 Message-Id: <1499498863-6865-1-git-send-email-dev@kresin.me> X-Mailer: git-send-email 2.7.4 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If clk_get returns an error, rt2x00dev->clk is set to NULL. In contrast to the common clock framework provided clk_get_rate(), at least the ramips and bcm63xx legacy implementation of the clk API access the rate member of the clk struct without a NULL check. This results into a kernel panic if we do not have a (SoC) clock. Call clk_get_rate only if we have a clock to fix the issues. This approach is similar to what is done in the kernel at various places. Usually clk_get_rate() is only called if clk_get_rate() doesn't return an error. Signed-off-by: Mathias Kresin --- Resend, the first mail had the wrong list in cc. drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c index d11c7b2..2a525b9 100644 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c @@ -2059,6 +2059,9 @@ static void rt2800_config_lna_gain(struct rt2x00_dev *rt2x00dev, static inline bool rt2800_clk_is_20mhz(struct rt2x00_dev *rt2x00dev) { + if (!rt2x00dev->clk) + return 0; + return clk_get_rate(rt2x00dev->clk) == 20000000; }