From patchwork Tue Jan 17 09:27:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Chow X-Patchwork-Id: 644042 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 490EDC3DA78 for ; Tue, 17 Jan 2023 10:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236477AbjAQKts (ORCPT ); Tue, 17 Jan 2023 05:49:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236200AbjAQKtk (ORCPT ); Tue, 17 Jan 2023 05:49:40 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5A94302BF; Tue, 17 Jan 2023 02:49:38 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id mp20so27778842ejc.7; Tue, 17 Jan 2023 02:49:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CuaI7HnIZyG0fRa/jgz3CE2/4ZxeGjEPtxv49RcTc3c=; b=BulVPYSG/zGDhw+AdNH2RQMc/BdqfZwU0TOqLpIX/pTvsgd97KpkpF2maR8OEQuB7z xT5atGxwfIHBEPrnhWiIAveMxT2rRlkoyO/sEke9V2Uit6E0jR8/4n0pn0M5QK8yUzRu IZiB/XrGboUcBD8IVbcHHYh4JXzSXadNY3NnnB5fqgSHN7qw5e2G8PxKgYX9wjb9sDT9 wm+U+JOsO4RF0VqU0hJZk5f2ZbOfkA2eoS+jLRxd0++7u+65IuUzR5LPQyOF1AWsA/nl +8mGn7BKKVUY6tnsvjfuSs0IKDSe8oVb2vYuqB6aDLVBxJ4pJOuRGl/dSCImMWBSneAJ vGDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CuaI7HnIZyG0fRa/jgz3CE2/4ZxeGjEPtxv49RcTc3c=; b=g5Sam6JGCR1lsppWsn/bO7qrFxqGHhJPBukVwdsqeRfNuFEvAxhzkIoU3cGccJ6/5V ZcF9d5BjI290R3RcU+oVlvJ47LXhj2ecSp7ZpFNiRjLYXFGVia0+LeowSJSoPOYJUtei nqMBIxnFf8GzcvwHlM2GOmLmKJTArPG+amvYymdjmzHyoYcmyaSdabDSYncP1mdduxrX ctPsTxQkDmhx8iuNHTQqHtJl3G03Y4EUsiBf1JV8Bk3oLBPr83T32opWBxpnm9vSUqUJ fbCs4UXh3jYNoBTlnVIlkkJ7BWvgCp6Jwn8txVpGGD7J+NcTMRu1PSIydwYA70/J6w33 ve9Q== X-Gm-Message-State: AFqh2kog7lJNSrc+ftCktxoeRRzFOzHBIEMpE8mroAQGtwXG8FsHeeDQ r5CMd59bOiuSjd+6Q8MWrb2tAe1SApACWA== X-Google-Smtp-Source: AMrXdXuMjOXZPp0x4cT+w3EpgnBoxWwZ8qUrmVfris5ntiId9iczztwI96C0i7ABZPvkXhSzoxVMgw== X-Received: by 2002:a17:906:1c81:b0:86f:d1c4:ed08 with SMTP id g1-20020a1709061c8100b0086fd1c4ed08mr2267497ejh.69.1673952578503; Tue, 17 Jan 2023 02:49:38 -0800 (PST) Received: from [0.0.0.0] (tor-exit-13.zbau.f3netze.de. [2a0b:f4c0:16c:13::1]) by smtp.gmail.com with ESMTPSA id v18-20020aa7dbd2000000b0049ac6f53e6asm1877329edt.80.2023.01.17.02.49.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 02:49:38 -0800 (PST) From: Edward Chow X-Google-Original-From: Edward Chow To: lpieralisi@kernel.org, toke@toke.dk, kvalo@kernel.org Cc: linux-pci@vger.kernel.org, robh@kernel.org, linux-wireless@vger.kernel.org, ath10k@lists.infradead.org, Edward Chow Subject: [PATCH 2/3] wifi: ath9k: stop loading incompatible DT cal data Date: Tue, 17 Jan 2023 17:27:46 +0800 Message-Id: <20230117092746.1149155-1-equu@openmail.cc> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Loading calibration data from an OF device tree node not declared compatible with the device (e.g. a PCI device with calibration data from corresponding DT node gets replaced, so the newly installed device become incompatible with the node) or driver may lead to fatal result, e.g. kernel panic. The driver should check whether the DT node corresponding to the device compatible with it, and load calibration data only from compatible node. Signed-off-by: Edward Chow --- drivers/net/wireless/ath/ath9k/ath9k.h | 1 + drivers/net/wireless/ath/ath9k/init.c | 26 ++++++++++++++++++++++++++ drivers/net/wireless/ath/ath9k/pci.c | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h index 2cc23605c9fc..4f6f0383a5f8 100644 --- a/drivers/net/wireless/ath/ath9k/ath9k.h +++ b/drivers/net/wireless/ath/ath9k/ath9k.h @@ -35,6 +35,7 @@ struct ath_node; struct ath_vif; extern struct ieee80211_ops ath9k_ops; +extern struct pci_driver ath_pci_driver; extern int ath9k_modparam_nohwcrypt; extern int ath9k_led_blink; extern bool is_ath9k_unloaded; diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c index 4f00400c7ffb..f88a48e8456b 100644 --- a/drivers/net/wireless/ath/ath9k/init.c +++ b/drivers/net/wireless/ath/ath9k/init.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -577,6 +578,31 @@ static int ath9k_nvmem_request_eeprom(struct ath_softc *sc) size_t len; int err; + /* devm_nvmem_cell_get() will get a cell first from the OF + * DT node representing the given device with nvmem-cell-name + * "calibration", and from the global lookup table as a fallback, + * and an ath9k device could be either a pci one or a platform one. + * + * If the OF DT node is not compatible with the real device, the + * calibration data got from the node should not be applied. + * + * dev_is_pci(sc->dev) && ( no OF node || caldata not from node + * || not compatible ) -> do not use caldata . + * + * !dev_is_pci(sc->dev) -> always use caldata . + */ + if (dev_is_pci(sc->dev) && + (!sc->dev->of_node || + !of_property_match_string(sc->dev->of_node, + "nvmem-cell-names", + "calibration") || + !of_pci_node_match_driver(sc->dev->of_node, + &ath_pci_driver))) + /* follow the "just return 0;" convention as + * noted below. + */ + return 0; + cell = devm_nvmem_cell_get(sc->dev, "calibration"); if (IS_ERR(cell)) { err = PTR_ERR(cell); diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c index a074e23013c5..fcb19761e60d 100644 --- a/drivers/net/wireless/ath/ath9k/pci.c +++ b/drivers/net/wireless/ath/ath9k/pci.c @@ -1074,7 +1074,7 @@ static SIMPLE_DEV_PM_OPS(ath9k_pm_ops, ath_pci_suspend, ath_pci_resume); MODULE_DEVICE_TABLE(pci, ath_pci_id_table); -static struct pci_driver ath_pci_driver = { +struct pci_driver ath_pci_driver = { .name = "ath9k", .id_table = ath_pci_id_table, .probe = ath_pci_probe, From patchwork Tue Jan 17 10:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mad Horse X-Patchwork-Id: 644045 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBF36C63797 for ; Tue, 17 Jan 2023 10:03:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236206AbjAQKDG (ORCPT ); Tue, 17 Jan 2023 05:03:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236226AbjAQKC5 (ORCPT ); Tue, 17 Jan 2023 05:02:57 -0500 X-Greylist: delayed 75 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 17 Jan 2023 02:02:54 PST Received: from smtp161.vfemail.net (smtp161.vfemail.net [146.59.185.161]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E67CD2B0A1 for ; Tue, 17 Jan 2023 02:02:54 -0800 (PST) Received: (qmail 4887 invoked from network); 17 Jan 2023 10:02:52 +0000 Received: from localhost (HELO nl101-3.vfemail.net) () by smtpout.vfemail.net with ESMTPS (ECDHE-RSA-AES256-GCM-SHA384 encrypted); 17 Jan 2023 10:02:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=vfemail.net; h=message-id :date:mime-version:from:subject:to:cc:references:in-reply-to :content-type:content-transfer-encoding; s=2018; bh=VN39zSHTyvbe bEFmumo5qWyWwXFTsOMjCR20O6qfWqg=; b=ZB5YuO0/3M8Nrkx8isoAh4khLiu7 fbYKjG4cu1LdqO98M4RqXJoa7QBk7Mv+6V1swDsVvzCTgLW1YPfnQOEw+CKU4PMr h+WmwXmY+kwnM7IY4I3ZcaYek5UMDNGLEaUbEAovD3BPd0DCfiv7xzxIr8jHgi6y vZq3j3+inpTeNgA= Received: (qmail 68063 invoked from network); 17 Jan 2023 10:02:52 -0000 Received: by simscan 1.4.0 ppid: 67983, pid: 68056, t: 0.4235s scanners:none Received: from unknown (HELO bmwxMDEudmZlbWFpbC5uZXQ=) (ZXF1dUBvcGVubWFpbC5jYw==@MTkyLjE2OC4xLjE5Mg==) by nl101.vfemail.net with ESMTPA; 17 Jan 2023 10:02:51 -0000 Message-ID: <8a9332b2-47ff-7f5f-cb11-667e6d6f5d9d@openmail.cc> Date: Tue, 17 Jan 2023 18:02:45 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 From: Mad Horse Subject: [PATCH 3/3] wifi: ath10k: only load compatible DT cal data To: lpieralisi@kernel.org, toke@toke.dk, kvalo@kernel.org Cc: linux-pci@vger.kernel.org, robh@kernel.org, linux-wireless@vger.kernel.org, ath10k@lists.infradead.org, Edward Chow References: Content-Language: en-US In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Loading calibration data from an OF device tree node not declared compatible with the device (e.g. a PCI device with calibration data from corresponding DT node gets replaced, so the newly installed device become incompatible with the node) or driver may lead to fatal result, e.g. kernel panic. The driver should check whether the DT node corresponding to the device compatible with it, and load calibration data only from compatible node. Signed-off-by: Edward Chow --- drivers/net/wireless/ath/ath10k/core.c | 28 ++++++++++++++++++++++++++ drivers/net/wireless/ath/ath10k/pci.c | 2 +- drivers/net/wireless/ath/ath10k/pci.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index 5eb131ab916f..e4d7ec7f3b59 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -26,6 +26,7 @@ #include "testmode.h" #include "wmi-ops.h" #include "coredump.h" +#include "pci.h" unsigned int ath10k_debug_mask; EXPORT_SYMBOL(ath10k_debug_mask); @@ -1958,6 +1959,33 @@ static int ath10k_download_cal_nvmem(struct ath10k *ar, const char *cell_name) size_t len; int ret; + /* devm_nvmem_cell_get() will get a cell first from the OF + * DT node representing the given device with nvmem-cell-name + * "calibration", and from the global lookup table as a fallback, + * and an ath9k device could be either a pci one or a platform one. + * + * If the OF DT node is not compatible with the real device, the + * calibration data got from the node should not be applied. + * + * dev_is_pci(ar->dev) && ( no OF node || caldata not from node + * || not compatible ) -> do not use caldata . + * + * !dev_is_pci(ar->dev) -> always use caldata . + * + * The judgement for compatibility differs with ath9k for many + * DT using "qcom,ath10k" as compatibility string. + */ + if (dev_is_pci(ar->dev) && + (!ar->dev->of_node || + (of_property_match_string(ar->dev->of_node, + "nvmem-cell-names", + cell_name) < 0) || + !of_device_is_compatible(ar->dev->of_node, + "qcom,ath10k") || + !of_pci_node_match_device(ar->dev->of_node, + &ath10k_pci_driver))) + return ERR_PTR(-ENOENT); + cell = devm_nvmem_cell_get(ar->dev, cell_name); if (IS_ERR(cell)) { ret = PTR_ERR(cell); diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c index 728d607289c3..5d9f6046f8cf 100644 --- a/drivers/net/wireless/ath/ath10k/pci.c +++ b/drivers/net/wireless/ath/ath10k/pci.c @@ -3780,7 +3780,7 @@ static SIMPLE_DEV_PM_OPS(ath10k_pci_pm_ops, ath10k_pci_pm_suspend, ath10k_pci_pm_resume); -static struct pci_driver ath10k_pci_driver = { +struct pci_driver ath10k_pci_driver = { .name = "ath10k_pci", .id_table = ath10k_pci_id_table, .probe = ath10k_pci_probe, diff --git a/drivers/net/wireless/ath/ath10k/pci.h b/drivers/net/wireless/ath/ath10k/pci.h index 480cd97ab739..de676797b736 100644 --- a/drivers/net/wireless/ath/ath10k/pci.h +++ b/drivers/net/wireless/ath/ath10k/pci.h @@ -209,6 +209,8 @@ static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar) #define DIAG_ACCESS_CE_TIMEOUT_US 10000 /* 10 ms */ #define DIAG_ACCESS_CE_WAIT_US 50 +extern struct pci_driver ath10k_pci_driver; + void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value); void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val); void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val);