From nobody Sun Dec 14 12:15:14 2025 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 A7A921C2320 for ; Fri, 28 Jun 2024 15:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719588350; cv=none; b=B7C8w6B6c/UUSafWUqlswxx8+QpXhdx79rL3YCjmr1TGlbR7v1n3Xa+8zz86oKned5a2h9Kapb1i2yV/5bzRtVSlVHCR29fSmM7aA4GgBQzhC89+6mnWF0l2QQJHrtsqZlFv0uiGfZ0vRZhFTQrXGIdLV82BuF/d/xGE962CyaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719588350; c=relaxed/simple; bh=UvSwhyFECv13QdR1EO2R0VAa317NR2PeY6pJ2CNujRs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=S0f4/g0qXY83Ecu0NZWi4s04Jdz4bP6DowkZ+6/f1nfmRrOhd9hBB0OMgU5PPtgvk9Jk0yoJNu9cAlPAO0uLD8w8UPQ22JczEeYrki5PFI0KfbWYl0ATbrGBVgzgmj82YNLQiEQyMktm1qWptoO2w9ikys8ZLimP9NG7G6NXCsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=timesys.com; spf=pass smtp.mailfrom=timesys.com; dkim=pass (2048-bit key) header.d=timesys-com.20230601.gappssmtp.com header.i=@timesys-com.20230601.gappssmtp.com header.b=L41KM4kH; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=timesys.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=timesys.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=timesys-com.20230601.gappssmtp.com header.i=@timesys-com.20230601.gappssmtp.com header.b="L41KM4kH" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52ce674da85so827070e87.2 for ; Fri, 28 Jun 2024 08:25:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timesys-com.20230601.gappssmtp.com; s=20230601; t=1719588347; x=1720193147; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=X+DJpOm4RfaDE2zD0n6roADp/UbGD++A0Jdm0qwsA/0=; b=L41KM4kHoe+f5blQIv/E5U/zchAgZUfcO02r5Fpcz2LA0Bao6ge0qa7ilh1Hur8VdF b/SQb4AG3cA+V9maJTiQEeuF0WYmMVYGUpIviTeKRYDNNTStexnI94FNGjYstyiXJKIQ FIsTIkViATPDPPK+AoXDw9HZgaAO7gGRm32NOOTba7BuDjJ5uv8mFmHee8ONX+lEkR/r dBD+bAVniyjyHNXj6TxLrmLSWIas5n6xlUOluyw3C/usn3hUHlL+eje88wd/ZrtcqcwE viu9qucu1Aj3QgQaSiKGcMaR1pF411IW7UPQ6JextoQqi4emGX2XzpHFuPK8UFpbPdLL vYqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719588347; x=1720193147; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X+DJpOm4RfaDE2zD0n6roADp/UbGD++A0Jdm0qwsA/0=; b=CHPhPTs4Bui1tdjqFYtzSepcpGLRR98/mUCzO9Sx1ZXv918MjSih+Idud8zeuA4XxK 9Q+CXYVBao/xN7xYCF/1NcH1gkq/jbPSKyaQxFR9cYkZ25/xxpBRAzKbh4Ku8+uhje6Y XfuU5+GR2VWLocpY7PCmrF5vT9AJZg/mBYXZnER2Dw6wu0z4zv3bvSGrDNz8IVMzqGwB uF28D2N13Av47fBa6Te8oHOuqS2ydMEtY3O2Ka7R5p6+zEaLp3M54nZiaqrVX2WYATyc KE9ysH1yZMuyU7LTtHq71ZlFf45dSPkD0EBLGPh5dRx89l07NncACsfX5Wtap6p2MafV eUdw== X-Forwarded-Encrypted: i=1; AJvYcCXSAmBeEW95rtcHN+loFgQsrvZqdB1E2xJH4wuY/AVJmPKTTvfU+q3Y5CjQUPrVBvavXCxwyAwCJMl1G+SHa0kOBj1DSqhZq+/kpWoJ X-Gm-Message-State: AOJu0YxmDY+Pxs6jzeBm2Y5V4Jxt8RYyN3+i3NGWn9Oca1KJsuTZHjFV ssAjN8VQKP38wOCFvR9d02WuhdKDqj9U9ZpHBwFWx29qf06mmmrBEnoSo2hXPe9bhsOy6ZVEMAw WWkw= X-Google-Smtp-Source: AGHT+IFD5IqMU8Z9yWTJ4dYm8EbSz+bq8UmAEO+yhkdwWrTyGoL0GitM5iY9qryAl/yy/AzXcQbxgg== X-Received: by 2002:a05:6512:3e0a:b0:52c:e3c7:941e with SMTP id 2adb3069b0e04-52ce3c799f0mr16299518e87.47.1719588346588; Fri, 28 Jun 2024 08:25:46 -0700 (PDT) Received: from localhost.localdomain ([91.216.213.152]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72ab06517csm88351466b.105.2024.06.28.08.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jun 2024 08:25:46 -0700 (PDT) From: Piotr Wojtaszczyk To: Vladimir Zapolskiy , Piotr Wojtaszczyk , Andi Shyti , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [Patch v6] i2c: pnx: Fix potential deadlock warning from del_timer_sync() call in isr Date: Fri, 28 Jun 2024 17:25:42 +0200 Message-Id: <20240628152543.281105-1-piotr.wojtaszczyk@timesys.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When del_timer_sync() is called in an interrupt context it throws a warning because of potential deadlock. The timer is used only to exit from wait_for_completion() after a timeout so replacing the call with wait_for_completion_timeout() allows to remove the problematic timer and its related functions altogether. Signed-off-by: Piotr Wojtaszczyk --- Changes for v6: - Fixed typo in the patch subject Changes for v5: - Replaced wait_for_completion() with wait_for_completion_timeout(). - Removed unneded "alg_data->mif.timer" and its functions - Request irq with devm_request_irq() as before the patch - Renamed the patch and reword description for the new way to fix the warning Changes for v4: - Request irq with devm_request_threaded_irq() to prevent the warning drivers/i2c/busses/i2c-pnx.c | 48 ++++++++---------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c index a12525b3186b..f448505d5468 100644 --- a/drivers/i2c/busses/i2c-pnx.c +++ b/drivers/i2c/busses/i2c-pnx.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -32,7 +31,6 @@ struct i2c_pnx_mif { int ret; /* Return value */ int mode; /* Interface mode */ struct completion complete; /* I/O completion */ - struct timer_list timer; /* Timeout */ u8 * buf; /* Data buffer */ int len; /* Length of data buffer */ int order; /* RX Bytes to order via TX */ @@ -117,24 +115,6 @@ static inline int wait_reset(struct i2c_pnx_algo_data = *data) return (timeout <=3D 0); } =20 -static inline void i2c_pnx_arm_timer(struct i2c_pnx_algo_data *alg_data) -{ - struct timer_list *timer =3D &alg_data->mif.timer; - unsigned long expires =3D msecs_to_jiffies(alg_data->timeout); - - if (expires <=3D 1) - expires =3D 2; - - del_timer_sync(timer); - - dev_dbg(&alg_data->adapter.dev, "Timer armed at %lu plus %lu jiffies.\n", - jiffies, expires); - - timer->expires =3D jiffies + expires; - - add_timer(timer); -} - /** * i2c_pnx_start - start a device * @slave_addr: slave address @@ -259,8 +239,6 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data= *alg_data) ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie), I2C_REG_CTL(alg_data)); =20 - del_timer_sync(&alg_data->mif.timer); - dev_dbg(&alg_data->adapter.dev, "%s(): Waking up xfer routine.\n", __func__); @@ -276,8 +254,6 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data= *alg_data) ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie), I2C_REG_CTL(alg_data)); =20 - /* Stop timer. */ - del_timer_sync(&alg_data->mif.timer); dev_dbg(&alg_data->adapter.dev, "%s(): Waking up xfer routine after zero-xfer.\n", __func__); @@ -364,8 +340,6 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data = *alg_data) mcntrl_drmie | mcntrl_daie); iowrite32(ctl, I2C_REG_CTL(alg_data)); =20 - /* Kill timer. */ - del_timer_sync(&alg_data->mif.timer); complete(&alg_data->mif.complete); } } @@ -400,8 +374,6 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev= _id) mcntrl_drmie); iowrite32(ctl, I2C_REG_CTL(alg_data)); =20 - /* Stop timer, to prevent timeout. */ - del_timer_sync(&alg_data->mif.timer); complete(&alg_data->mif.complete); } else if (stat & mstatus_nai) { /* Slave did not acknowledge, generate a STOP */ @@ -419,8 +391,6 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev= _id) /* Our return value. */ alg_data->mif.ret =3D -EIO; =20 - /* Stop timer, to prevent timeout. */ - del_timer_sync(&alg_data->mif.timer); complete(&alg_data->mif.complete); } else { /* @@ -453,9 +423,8 @@ static irqreturn_t i2c_pnx_interrupt(int irq, void *dev= _id) return IRQ_HANDLED; } =20 -static void i2c_pnx_timeout(struct timer_list *t) +static void i2c_pnx_timeout(struct i2c_pnx_algo_data *alg_data) { - struct i2c_pnx_algo_data *alg_data =3D from_timer(alg_data, t, mif.timer); u32 ctl; =20 dev_err(&alg_data->adapter.dev, @@ -472,7 +441,6 @@ static void i2c_pnx_timeout(struct timer_list *t) iowrite32(ctl, I2C_REG_CTL(alg_data)); wait_reset(alg_data); alg_data->mif.ret =3D -EIO; - complete(&alg_data->mif.complete); } =20 static inline void bus_reset_if_active(struct i2c_pnx_algo_data *alg_data) @@ -514,6 +482,7 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *= msgs, int num) struct i2c_msg *pmsg; int rc =3D 0, completed =3D 0, i; struct i2c_pnx_algo_data *alg_data =3D adap->algo_data; + unsigned long time_left; u32 stat; =20 dev_dbg(&alg_data->adapter.dev, @@ -548,7 +517,6 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *= msgs, int num) dev_dbg(&alg_data->adapter.dev, "%s(): mode %d, %d bytes\n", __func__, alg_data->mif.mode, alg_data->mif.len); =20 - i2c_pnx_arm_timer(alg_data); =20 /* initialize the completion var */ init_completion(&alg_data->mif.complete); @@ -564,7 +532,10 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg = *msgs, int num) break; =20 /* Wait for completion */ - wait_for_completion(&alg_data->mif.complete); + time_left =3D wait_for_completion_timeout(&alg_data->mif.complete, + alg_data->timeout); + if (time_left =3D=3D 0) + i2c_pnx_timeout(alg_data); =20 if (!(rc =3D alg_data->mif.ret)) completed++; @@ -653,7 +624,10 @@ static int i2c_pnx_probe(struct platform_device *pdev) alg_data->adapter.algo_data =3D alg_data; alg_data->adapter.nr =3D pdev->id; =20 - alg_data->timeout =3D I2C_PNX_TIMEOUT_DEFAULT; + alg_data->timeout =3D msecs_to_jiffies(I2C_PNX_TIMEOUT_DEFAULT); + if (alg_data->timeout <=3D 1) + alg_data->timeout =3D 2; + #ifdef CONFIG_OF alg_data->adapter.dev.of_node =3D of_node_get(pdev->dev.of_node); if (pdev->dev.of_node) { @@ -673,8 +647,6 @@ static int i2c_pnx_probe(struct platform_device *pdev) if (IS_ERR(alg_data->clk)) return PTR_ERR(alg_data->clk); =20 - timer_setup(&alg_data->mif.timer, i2c_pnx_timeout, 0); - snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name), "%s", pdev->name); =20 --=20 2.25.1