From patchwork Sun Dec 25 08:37:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 36462 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp450906wrt; Sun, 25 Dec 2022 01:03:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXv4RJ5qW3calQW//XZrYwZOA1K4oiBWI0hnI3Znb5liThaHoswpiLv9BTxrF1TkO03JdWOc X-Received: by 2002:a17:906:3513:b0:7ff:7205:414e with SMTP id r19-20020a170906351300b007ff7205414emr11607888eja.69.1671958981272; Sun, 25 Dec 2022 01:03:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671958981; cv=none; d=google.com; s=arc-20160816; b=ydeeC62mfhb8UJemQH8O88WOddE4ChC9QneVZrfhmVTfszEEljUwFFBaRFwkJ6xX96 yhoV3LjwbnPx4CUtfQBToN4VfJbHGMzofygp6uCnfl1My9zX7BiVTl+6WHHiMskFJve1 fS6oCTQfyyj5OFC7i4Ar85Yj5GRccpd77GGUtV5UU8DRMMovZ6V3T73IH2WX9cajoKzC zuaPLRVLb85tA63cu5IP9RPQHWw7H0C80LO8w86x44UPZzA23t0AAXJfusDtpoXLkPh+ kwsvgJre7McvaVrr0DFUd7TPN08CFFpcR+negSywSagFkqpZdVr60LXWsOHZ4cqzJC82 zpVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=SwvUk8nCc2kiHmnECJ1iMld3VFTwbnQ/Nb7HP3LTcH0=; b=gvNCY11x5GBq3ZfH/YjAwOCKWqMtGvkZubn7mowOM5N7g7ZAwvRQDFf/tNZlJmIaUX 7vlZjXrhG+4rS9gDzG/Kq30lRMgwBvm5cFXlsx7SnQxsAC+++EdM3RNd81kwnE5SSLKe Z6IHeDrAPHUpopMFMSf3sD6E0c+5zWGvPP5WVrTALNYZSNzrvWlQqgEi2Yxc17Bf3+Gd 3Yv1HhFpgj1GA1XSm1ex62UQSkcj0TUgXv3Io6J7yBXm2ivSvf5N1S53o2sqT1WU2C7P ofixYTPAEFNiwcqExCqiRzt61BlBZdSaGWScCZbsg8IeEFSpoplmo0vWh0ydHFZHVCn7 O8MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NkivvfbR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id el15-20020a056402360f00b0048321d887b5si3100756edb.516.2022.12.25.01.02.35; Sun, 25 Dec 2022 01:03:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NkivvfbR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230283AbiLYIhX (ORCPT + 99 others); Sun, 25 Dec 2022 03:37:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiLYIhV (ORCPT ); Sun, 25 Dec 2022 03:37:21 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B25BCEF for ; Sun, 25 Dec 2022 00:37:20 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id gh17so20916198ejb.6 for ; Sun, 25 Dec 2022 00:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=SwvUk8nCc2kiHmnECJ1iMld3VFTwbnQ/Nb7HP3LTcH0=; b=NkivvfbR9LwyzM3qir50hBLkzuM5o1CupKhC9o9epUuPyHJlZxQpbm//x0yfHXZO1W ZHrk2ojmM3lFFarsZgtwZDAtktz2mPZFWGnaYswffE61Cir7JXL7zrX+S0++hA/WXvnZ NKuBjZ0oHDs1rJKQ6HwKWj2E/VZ1KdIJwyiq0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SwvUk8nCc2kiHmnECJ1iMld3VFTwbnQ/Nb7HP3LTcH0=; b=3uZC/YAYULKeWDcdDtwMt2QA8roiS8aYr4K9+JTIcYDY1pxIcLC4tsbomA/7ednsk2 ZFKPYy6hYYbVy3DztcZXJWq03ubGGJyhIjY4nzOZolOnNWI7+WRUbBxFrEs/a49pCvhV WO7dHG1lX3nqydH5LSYs5tNmTZOJyAu35iQ13km5NCsqi7r679IuXyn3CuwR6EcM1us2 ImhWx8u3n06Kf4ToeQOlWevwwYa1Zz8ZqcootgGfD5WpQRyIeoqTSbsOt+MxPcOLlQD/ Wsm6ArTb/q602RNL8QimQpjdvW/0wmKqOfV7qTD6jhhZwzwSTqtgzkTrG0kcCK116S3j kBCg== X-Gm-Message-State: AFqh2kpQezKFxA0inGV3zRuD/5UswEFZtgJbGgzvo+WnDcwDUiXXB/Di Fr66gMMBEqpsyT7iE5CWECmVNQ94eta1c3/B X-Received: by 2002:a17:907:3888:b0:83f:757e:f182 with SMTP id sq8-20020a170907388800b0083f757ef182mr12114821ejc.65.1671957438627; Sun, 25 Dec 2022 00:37:18 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id 1-20020a170906200100b007ae1e528390sm3378820ejo.163.2022.12.25.00.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Dec 2022 00:37:18 -0800 (PST) From: Ricardo Ribalda Date: Sun, 25 Dec 2022 09:37:12 +0100 Subject: [PATCH] spi: mediatek: Enable irq before the spi registration MIME-Version: 1.0 Message-Id: <20221225-mtk-spi-fixes-v1-0-bb6c14c232f8@chromium.org> To: Matthias Brugger , Mark Brown , AngeloGioacchino Del Regno Cc: linux-mediatek@lists.infradead.org, Ricardo Ribalda , linux-arm-kernel@lists.infradead.org, Daniel Golle , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=2362; i=ribalda@chromium.org; h=from:subject:message-id; bh=S9r6wjmERP8avI49s18Jhy8ipRj4r0kR4VhZqUULP4Y=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjqAu5PnnA9Qc3bEgfnFKq/SZnVuwBousGA4xtFKDt WjkgicOJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY6gLuQAKCRDRN9E+zzrEiLy/D/ 9U86jlFiSKdjPyYa5uHCJN9qD94eSk9psQFmvWnfmiPLfrQssy1tzhSlNyfqQSLZYIt3MqYaQIlb23 doEsdMl3TUww8eiAR2xkEWlKmU7v99oSDeagkN4Lu8xGe65Sqq/48QFEgJX32CXUbpGXQjYfgK7Ki0 lcPjp/qjB+TU7FfwQ15+Xi1+W4Uh43/LGA/y6ZuLF7cn5hnZQdEp8QdgHIuDMOTgadPAZhJfW67rx6 nMDq3gfCrobTYpc0eb9cu04B04MOOqFAyLDyzIhMxiocd002uWttTeV7+tMVl4PnKHeKO3R8CqjzFO 6HURnumDGJ6HE7FZBacH6hav347sLuvO6KZhqyJJfOM4z+wZScSEu3/E0xcpoScqBkrKDlVM6p345M h2b4YZ34T++fpmeCqg6mAXh+q0PItKBT13pLL3l+9fM/U6ZhYdtHhSqgKLF+Al1M1PKGDe+ymQ6MoA MqICUc68JAkf6FZtUnmj/WXVMqAKLC0Pv0HYHxBURjz2vqHTYBj8MQXQ5BoRBPXtveGCB9y9TYAy2U YnTnIaWc5nr/HNC+EDJnx7+q2uave3m7QpVXtodJdxPUJIXcWQAYijS6pR7Nzt1NUQceSR65Iwdf9C C+s8AvOuqoDkdNLn4QFmSIRs8kd8isb5jY1YvrgBdKKw8tvUiGFkOwR+Vbsg== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753176060756558064?= X-GMAIL-MSGID: =?utf-8?q?1753176060756558064?= If the irq is enabled after the spi si registered, there can be a race with the initialization of the devices on the spi bus. Eg: mtk-spi 1100a000.spi: spi-mem transfer timeout spi-nor: probe of spi0.0 failed with error -110 Unable to handle kernel NULL pointer dereference at virtual address 0000000000000010 ... Call trace: mtk_spi_can_dma+0x0/0x2c Fixes: c6f7874687f7 ("spi: mediatek: Enable irq when pdata is ready") Reported-by: Daniel Golle Signed-off-by: Ricardo Ribalda Tested-by: Daniel Golle --- spi: mediatek: Fix init order (again) Hi Mark Here is a fixup of the previous patch. Daniel, can you confirm that it works on your hardware? Thanks and sorry for annoyance. To: Mark Brown To: Matthias Brugger To: AngeloGioacchino Del Regno Cc: linux-spi@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-mediatek@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: Daniel Golle --- drivers/spi/spi-mt65xx.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- base-commit: 45b3cd900bf8d1a3cd7cf48361df8c09ae5b4009 change-id: 20221225-mtk-spi-fixes-99c863a6fdf1 Best regards, diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 6de8360e5c2a..9eab6c20dbc5 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -1253,6 +1253,11 @@ static int mtk_spi_probe(struct platform_device *pdev) dev_notice(dev, "SPI dma_set_mask(%d) failed, ret:%d\n", addr_bits, ret); + ret = devm_request_irq(dev, irq, mtk_spi_interrupt, + IRQF_TRIGGER_NONE, dev_name(dev), master); + if (ret) + return dev_err_probe(dev, ret, "failed to register irq\n"); + pm_runtime_enable(dev); ret = devm_spi_register_master(dev, master); @@ -1261,13 +1266,6 @@ static int mtk_spi_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "failed to register master\n"); } - ret = devm_request_irq(dev, irq, mtk_spi_interrupt, - IRQF_TRIGGER_NONE, dev_name(dev), master); - if (ret) { - pm_runtime_disable(dev); - return dev_err_probe(dev, ret, "failed to register irq\n"); - } - return 0; }