Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp594968pxh; Tue, 9 Nov 2021 15:53:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2RBoPNokyquDNzo0eAgXdnnVl1SsPY+jfL6BWgY/UBlFydwqrnByjFtPm8JqfeuFxqBqQ X-Received: by 2002:a17:906:fcc8:: with SMTP id qx8mr14685189ejb.370.1636502000222; Tue, 09 Nov 2021 15:53:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636502000; cv=none; d=google.com; s=arc-20160816; b=o4120xR//gH2dOiKnJm5G8+Rbkvo6PLXyZWXvRkELTjH8EKRBRuwH6wBx2GXLFA5nR kiKrODtZWwHVy3YdJbpK37KsCO914E+9VButGbvtY54h0QdqCMgbx48FawrLkEHg/Nvz MRPhJbCRQgexPhEChoO4i3M7N/VaJRMYjIkp/6LlxYCDkomAhlSTQsuamylN5WqTQAD0 IK+rozkf7GUdqbhXsmD4wXUjHXzEYAy7gCqvGoGzSvbrwYoyq0OQmozM37wliAKipnWZ wPrCFBlA//rbU+8G+Dt1VPhaIVYkDnRF8FajQD3BBQdKJ/JEN4vwZ3y/Dj5f1/gXYCCH uNeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cQrJdMnrV6Addtv2oC/d+bVYYIdpcxEWMHdVTxWrRC8=; b=VR/2gdbTN/5iOaCjaWhc9FMPGMtxeSBvTBISgsG+McmR3VAelgkEc7dNM1bKEQiISW sS8DQh8W9SMTe2jXVEstaZfcGqkli1ZFn4voGlVf44Jqe7iIIZXArFasH5jBFrWWZnVG b9VDj+2bQLG71vzz6gG6ocRB6G/Cz/JiJyUFOA1cOmrsyL/U5Wzc8He8HhNqAaHnww9z yk2RGOLOfgXtcE83Jp8Y7LQdaNSaVv2fi0AonwFuHPap9s6lZhdinOy/+m6VH0bGyYo3 fry2V3t7D9BMtr5n4yDjkQ6TEj7Fj6Z+TlQ/aM1CuIiLJYBN9LAgUyODUfPlX124YZTi 6aDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@collabora.com header.s=mail header.b=wleihR17; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hj1si49061169ejc.555.2021.11.09.15.52.57; Tue, 09 Nov 2021 15:53:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@collabora.com header.s=mail header.b=wleihR17; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234362AbhKINvP (ORCPT + 97 others); Tue, 9 Nov 2021 08:51:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231169AbhKINvO (ORCPT ); Tue, 9 Nov 2021 08:51:14 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 710B6C061764; Tue, 9 Nov 2021 05:48:28 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: evelikov) with ESMTPSA id B67201F44F35 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=collabora.com; s=mail; t=1636465707; bh=5qEsGY70K1k5pgaloIKEQytSeQfjQfJo2OUEknVczDM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=wleihR17ZG3Cs+LG0bmtOLo1Ks2ViGbG58W0HJvT36b9dh9WLXqpknO58DQGJ6nXL heRFgAN/dDcSfTvP4P2zH+o+BUJq8Tuhc5V3kwWN/2O43PjhdczQ2OjOHvm19R1J6A EqoE0WTP8xL5d8nEDj0am4w/rcvXJy29VKIUiCzhBh4z5ZCkadA2KnbAz6Khu/4tlf vc5lknJcxNXCDCnEwJJQsW/3LVqDwpaUVJUAGuIzrdBfT7M7MA5sgzUCbdCQO9SA4O 0d5UnwN0PJayWve769ZArJ/uVJ+DsVhrpaPgV6XUQVjFtw+BAIFm3U6iOv92qM0h5W ZHXVlPVmJ5Cnw== Date: Tue, 9 Nov 2021 13:48:23 +0000 From: Emil Velikov To: Shreeya Patel Cc: linus.walleij@linaro.org, brgl@bgdev.pl, krisman@collabora.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: Re: [PATCH] gpio: Initialize gc->irq.domain before setting gc->to_irq Message-ID: References: <20211108214148.9724-1-shreeya.patel@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211108214148.9724-1-shreeya.patel@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Shreeya, all, On 2021/11/09, Shreeya Patel wrote: > There is a race in registering of gc->irq.domain when > probing the I2C driver. > This sometimes leads to a Kernel NULL pointer dereference > in gpiochip_to_irq function which uses the domain variable. > > To avoid this issue, set gc->to_irq after domain is > initialized. This will make sure whenever gpiochip_to_irq > is called, it has domain already initialized. > What is stopping the next developer to moving the assignment to the incorrect place? Aka should we add an inline comment about this? > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index abfbf546d159..9a6f7c265a91 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -1512,7 +1512,6 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc, > if (gc->to_irq) > chip_warn(gc, "to_irq is redefined in %s and you shouldn't rely on it\n", __func__); > Move the warning alongside the assignment? HTH Emil