Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1894923lqg; Mon, 4 Mar 2024 07:04:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUljlOXvtHBvX+UmlwJ4KMzADBq0YG7qQah3bEDpq9jJytqaeSx0KJv7qc49V/9tRy+h6T6c9z7I/A/kEVCmkVyvIW8A/HMkVQazxGTjw== X-Google-Smtp-Source: AGHT+IHix/Y7taVlie9/snryab4aL1+ofXpcHYdx42/BBHaM3oOsD+KvAwIjCsv7Ce0Bghp0xCKH X-Received: by 2002:a05:6512:e97:b0:513:2996:deb8 with SMTP id bi23-20020a0565120e9700b005132996deb8mr7334352lfb.39.1709564663006; Mon, 04 Mar 2024 07:04:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709564662; cv=pass; d=google.com; s=arc-20160816; b=lLe94fyrVD5C9ORuTyiKGhDfS7ERVMT3fHNiOkvlKR5nkasuE9mfaA6nM72Juwmu+T gqOcS2IuOFMZxZXGM+ZL9iIJ5ktObr4qsUjAv4tw6NbJloqux8C6TI2EdQioTkldQxsm fhWAC19fmWdqeiIdAx5EWsWLEbAcBVibhFvjYwFrO7bx9uWc3F/dsjZbdBV2dRsVY1/m 0u5nEzEcWoVrYL1CpoosV67gYxkW2HrIxb6EndY10iN/KZimeuhTps5XOYo0tjSPmtY8 EEYA99gJhapon/ArbDX02HWqkGnyysAkLJfxu+y1U5uUz7WGchKgk2DHT0GrVxacwbe+ /FvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rr1CkupL/CpRbe+EqqaBxhSvQjXDcliHnf1RebjuQoY=; fh=FhOwpacBCJqHjH732pMHpmsYVw3DyXeAiAfLIg9dzeM=; b=R4gOtDOJMbl8JdXwj6q6gtErP+j5k3+nGz76LMyyvmxLv8fHHAl2tGaVYVfzlZARoO 9erJVosOby7mmJ9SGj8oiKQz3v+z1JZMrhmanY/Hc+3lvzlA/X682hhOKsiJtlWj/YIA enHoRSBZRyPQDogGaWTXWCExuyMevkojjFNq8QH4Zz25Hu5TfBEqjmZI8cw1lVtvbt2z awhBzdWQyALl+4ryLTwzddOS+1hKwxRZOG++cgGk9B2O7QDyDxOTnIgdCrgDlVunin0F xR1HX9FxX1K3ccj85W3DYN4V9XbeKXKlnbmijpzxUPOcLs8DVDHKzaMfW71GP9GqdSc/ stZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jwlfxjuC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90773-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g12-20020aa7d1cc000000b005642bbeffacsi4067330edp.671.2024.03.04.07.04.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 07:04:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jwlfxjuC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90773-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8EA1B1F21DD4 for ; Mon, 4 Mar 2024 15:04:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9DD8746557; Mon, 4 Mar 2024 15:04:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jwlfxjuC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4EA33F9C0; Mon, 4 Mar 2024 15:04:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709564652; cv=none; b=BYg/4w4bqFAy/L+ONk5mySjLDUnR/zW3gU0vcWTWLpBtvYbq/4bWRhvcILXsKp55j/r80EBaA46Cf7Gkt+OZQRLbLjWmcqaERBcMS6A9EnFQQRPofjAnlVGeeEoNT/Kd516DhmuqHhVH9ZY+hZMDiPgd/JLkBCCDMFZG9njWoZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709564652; c=relaxed/simple; bh=sUkZRyJ98U5WESus3dO/qr3DdVnkuuLZdtsBx6GFUVE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i5q9YhPubmeMnF0/ZdEShYpEy7VUhXwjl+vprWbnVUQaYhbtQ7VxyGb7dJb9pYr8BBWSSmWKMe3j+Qt+K2qqJwfL6+7ZXPpAyQN4+e7Ue/s21hFMJGBD2JuOiX2viO4P+c147yOA8yoo4dfDiyx9h4yxMkap6Y6I5NlahGYT06E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jwlfxjuC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0096C433F1; Mon, 4 Mar 2024 15:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709564652; bh=sUkZRyJ98U5WESus3dO/qr3DdVnkuuLZdtsBx6GFUVE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jwlfxjuCNqmqMUTyLOsCMywTHyYeve0FUWr0Nh+EKoe2ysWjPj2eUeVAk6UPDA7Rv 6hUG+TK+e4c4aV6d7C04+jNVHrgWxRc0BsnUlU9zYmUS3QGjS+mRkhTRYK6FKmUwbX EkkGOGl6t0zo84p0autOIEGHNxXNtNWvWeH3t1Tel1fnt2pPgEj1OCzjb80BHwzSgP LMFNXe+diQiiY437/I5LByPyodDxfuIafqX7Qs8C4Ygt2yvMZJ5KovPKvm9fIRdWO3 rJCnfuj20yoyigyqm2E1CthVLJFcK5waVtglDg4+K14KBqPAunP9lpKuGh9EXmB/MF RCPNOOzzrWnzg== Date: Mon, 4 Mar 2024 16:04:08 +0100 From: Andi Shyti To: Jesper Nilsson Cc: Krzysztof Kozlowski , Alim Akhtar , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@axis.com, Andi Shyti Subject: Re: [PATCH] i2c: exynos5: Init data before registering interrupt handler Message-ID: References: <20240304-i2c_exynos5-v1-1-e91c889d2025@axis.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240304-i2c_exynos5-v1-1-e91c889d2025@axis.com> Hi Jesper, On Mon, Mar 04, 2024 at 12:01:14PM +0100, Jesper Nilsson wrote: > devm_request_irq() is called before we initialize the "variant" > member variable from of_device_get_match_data(), so if an interrupt > is triggered inbetween, we can end up following a NULL pointer > in the interrupt handler. > > This problem was exposed when the I2C controller in question was > (mis)configured to be used in both secure world and Linux. > > That this can happen is also reflected by the existing code that > clears any pending interrupts from "u-boot or misc causes". > > Move the clearing of pending interrupts and the call to > devm_request_irq() to the end of probe. I'm OK with moving the irq request at the end and I'm going to give my r-b anyway. There is still one comment below. > Additionally, return failure if we can't find a match in devicetree. > > Signed-off-by: Jesper Nilsson The way you are describing it you would need the Fixes tag here and this patch should be treated as a fix. Nevertheless, I think that it's odd that the device is sending interrupts at this phase and the real fix should be preventing the controller to send interrupts here. How have you tested this patch? > --- > drivers/i2c/busses/i2c-exynos5.c | 32 ++++++++++++++++++-------------- > 1 file changed, 18 insertions(+), 14 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c > index 385ef9d9e4d4..eba717e5cad7 100644 > --- a/drivers/i2c/busses/i2c-exynos5.c > +++ b/drivers/i2c/busses/i2c-exynos5.c > @@ -906,24 +906,14 @@ static int exynos5_i2c_probe(struct platform_device *pdev) > i2c->adap.algo_data = i2c; > i2c->adap.dev.parent = &pdev->dev; > > - /* Clear pending interrupts from u-boot or misc causes */ > - exynos5_i2c_clr_pend_irq(i2c); > - > spin_lock_init(&i2c->lock); > init_completion(&i2c->msg_complete); > > - i2c->irq = ret = platform_get_irq(pdev, 0); > - if (ret < 0) > - goto err_clk; > - > - ret = devm_request_irq(&pdev->dev, i2c->irq, exynos5_i2c_irq, > - IRQF_NO_SUSPEND, dev_name(&pdev->dev), i2c); > - if (ret != 0) { > - dev_err(&pdev->dev, "cannot request HS-I2C IRQ %d\n", i2c->irq); > - goto err_clk; > - } > - > i2c->variant = of_device_get_match_data(&pdev->dev); > + if (!i2c->variant) { > + dev_err(&pdev->dev, "can't match device variant\n"); > + return -ENODEV; return dev_err_probe(), please. Andi