Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp400079rdh; Tue, 19 Dec 2023 02:16:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMR5vOijN3ziHPWFtbPpi6z3KojqPFwU6aPjeMY2IjQo2PXFd+pfsxyoB/BveAdPqwFKoW X-Received: by 2002:a05:6a20:4b8f:b0:194:a53f:52a9 with SMTP id fu15-20020a056a204b8f00b00194a53f52a9mr684729pzb.18.1702981010235; Tue, 19 Dec 2023 02:16:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702981010; cv=none; d=google.com; s=arc-20160816; b=qmXU/u/XDrByqAvNZTRzcDuchDwOOKgyV+tQd+Dg1XuzImlPLB8uEoZwDwATclXrz4 wTaINJxdWQGLJaHmC9iLpMOYzKxd5ntg1eQsacCpddX83DLb4B/fbodqMFV88ZY85IuY o3afl7bN+U4uwQhqZRmeUbe2Aln30VERXRB+Y4uQLHtDR74nhne5y1WRLEH4dcU0Zg6x 6Ox95SOeiPfeLxMCl2EfZldkIjwAW7yAhm6S5MS/6aVXjQmgjUxeIz62DvYkXK9cJV8i pRMWku32f2L4RJRd5fZgG+Oe/oikdjJmQDgU6e/JkeBqxzJ/oL9mB28qWzjkMOoIflnL 9Ekg== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from; bh=ngNJCfucOduDHyYME8qfNMRkE+l/Nb1B8dGYavE1NeA=; fh=rDQ+Brvi8X8MBGQj98Swf6ntKE0/lLPfVCCWuSkkQw8=; b=bgaFErEmRdYSwb5v9TkirNE6ngS9/DzgdIV31bVDa/FavJ5cf0lMA3d6x6p78lvVzQ q49D+IcNru9xVwDhSCAgRTdxq+bssgc4190lIjYFNfUR8F6RdsQwslta4str/hND3wxW NiqFDmi//kD6fGhbI8xukMFSQLwj9ywi/RtGKlB9rVextXxHLYpMOxgO4epELalgnv+t Nxm8hzV/c5VDxOhPx8u1Y80JrW8+Q3Onf2yLwvR/V0E7LkbHzTgkZ9kIrXEoyQf9hpdX cQXpj/fSt5Vwcf975S19s6N/Tehh362q5wn9k6huiCUxUsow1dD2AmKS1O7MoOKrrD7d QByg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-5005-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5005-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z17-20020a637e11000000b005cda3e56fa8si2849605pgc.468.2023.12.19.02.16.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 02:16:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5005-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-5005-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5005-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 525E3B23F4C for ; Tue, 19 Dec 2023 10:16:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65B151429E; Tue, 19 Dec 2023 10:16:39 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8729414281; Tue, 19 Dec 2023 10:16:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d3ae9d1109so4658255ad.0; Tue, 19 Dec 2023 02:16:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702980997; x=1703585797; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ngNJCfucOduDHyYME8qfNMRkE+l/Nb1B8dGYavE1NeA=; b=WN5s2EPI7uLY+S3QMmV7GCW85vKyppu0NUBe5VplsjuDWo+c7hjM4TSe3fDIYlrthw T7mpcyAntHR5t5cQs5K9Z6dK68WU0nF7FjMqJtGlO20aBnadFlYP01jCIPhX586g5sim 0r9BdAKb6KVTRrpQEkUZfEwLj24jqMo2bNwvAMtGsMWcN83pm2RrhN00rWuAxgYV00TW oD/HSve8cSaLCmcmU0lnqHe/u23c8pXAwgfITEKqeLS0n0iQZrVQuUnBZ9RRj04himkb ocNxQZXLfpAGt3jcmKv3L5J+mJKWscteWjds71q7Tc5T1VMoGFmPjO7IlhUeVG9JmCQu mYjw== X-Gm-Message-State: AOJu0YzLcfLYVcfwOY1ngkTKDvFt/ZuBL0TrI5XUTtXEse7l7K6oDcdi PlcQCweeL0ePDDsZ/xq/dBw= X-Received: by 2002:a17:902:db12:b0:1d3:dbdc:4c9d with SMTP id m18-20020a170902db1200b001d3dbdc4c9dmr1827575plx.3.1702980996630; Tue, 19 Dec 2023 02:16:36 -0800 (PST) Received: from tgsp-ThinkPad-X280.. ([223.148.84.115]) by smtp.gmail.com with ESMTPSA id q14-20020a170902dace00b001d08e08003esm20649688plx.174.2023.12.19.02.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 02:16:36 -0800 (PST) From: xiongxin To: fancer.lancer@gmail.com, hoan@os.amperecomputing.com, linus.walleij@linaro.org, brgl@bgdev.pl, andy@kernel.org Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, xiongxin , stable@kernel.org, Riwen Lu Subject: [PATCH v4] gpio: dwapb: mask/unmask IRQ when disable/enale it Date: Tue, 19 Dec 2023 18:16:20 +0800 Message-Id: <20231219101620.4617-1-xiongxin@kylinos.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In the hardware implementation of the i2c hid driver based on dwapb gpio irq, when the user continues to use the i2c hid device in the suspend process, the i2c hid interrupt will be masked after the resume process is finished. This is because the disable_irq()/enable_irq() of the dwapb gpio driver does not synchronize the irq mask register state. In normal use of the i2c hid procedure, the gpio irq irq_mask()/irq_unmask() functions are called in pairs. In case of an exception, i2c_hid_core_suspend() calls disable_irq() to disable the gpio irq. With low probability, this causes irq_unmask() to not be called, which causes the gpio irq to be masked and not unmasked in enable_irq(), raising an exception. Add synchronization to the masked register state in the dwapb_irq_enable()/dwapb_irq_disable() function. mask the gpio irq before disabling it. After enabling the gpio irq, unmask the irq. Fixes: 7779b3455697 ("gpio: add a driver for the Synopsys DesignWare APB GPIO block") Cc: stable@kernel.org Co-developed-by: Riwen Lu Signed-off-by: Riwen Lu Signed-off-by: xiongxin Acked-by: Serge Semin Reviewed-by: Andy Shevchenko --- v4: * Add patch tag information v3: * Modify the submitter's information v2: * Resubmit the patch to fix this exception from the dwapb gpio driver side. v1: * Resolve the exception from the IRQ core layer. (key point not found correctly) --- drivers/gpio/gpio-dwapb.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 4a4f61bf6c58..8c59332429c2 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c @@ -282,13 +282,15 @@ static void dwapb_irq_enable(struct irq_data *d) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct dwapb_gpio *gpio = to_dwapb_gpio(gc); + irq_hw_number_t hwirq = irqd_to_hwirq(d); unsigned long flags; u32 val; raw_spin_lock_irqsave(&gc->bgpio_lock, flags); - val = dwapb_read(gpio, GPIO_INTEN); - val |= BIT(irqd_to_hwirq(d)); + val = dwapb_read(gpio, GPIO_INTEN) | BIT(hwirq); dwapb_write(gpio, GPIO_INTEN, val); + val = dwapb_read(gpio, GPIO_INTMASK) & ~BIT(hwirq); + dwapb_write(gpio, GPIO_INTMASK, val); raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); } @@ -296,12 +298,14 @@ static void dwapb_irq_disable(struct irq_data *d) { struct gpio_chip *gc = irq_data_get_irq_chip_data(d); struct dwapb_gpio *gpio = to_dwapb_gpio(gc); + irq_hw_number_t hwirq = irqd_to_hwirq(d); unsigned long flags; u32 val; raw_spin_lock_irqsave(&gc->bgpio_lock, flags); - val = dwapb_read(gpio, GPIO_INTEN); - val &= ~BIT(irqd_to_hwirq(d)); + val = dwapb_read(gpio, GPIO_INTMASK) | BIT(hwirq); + dwapb_write(gpio, GPIO_INTMASK, val); + val = dwapb_read(gpio, GPIO_INTEN) & ~BIT(hwirq); dwapb_write(gpio, GPIO_INTEN, val); raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); } -- 2.34.1