Received: by 2002:a05:7412:d024:b0:f9:90c9:de9f with SMTP id bd36csp118166rdb; Wed, 20 Dec 2023 07:44:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFic5+fn8BpyiCm4Apveo0R2GRoSM7ag7k1+AqKq9ytmP/XWzjlFHtwap9jYJx58qU3hFNU X-Received: by 2002:a05:6870:5149:b0:1fa:fff7:4a15 with SMTP id z9-20020a056870514900b001fafff74a15mr26544742oak.9.1703087046853; Wed, 20 Dec 2023 07:44:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703087046; cv=none; d=google.com; s=arc-20160816; b=FE/PcfDdZOu0iS8tkgdBhgNGnm9iSOhKquANtS/1lxG/xnaMOvXicgKx6cxE8uPoG8 ZCy5vFiBNdKnoGLc42yXSr8xvytTSo6S9V4kmpvqtayx34rVmssM+aWppv05MG6LfMKe Dl0fDiGkAZu7zH8r7LgHA9SY50KWbWQGFAUx8FWMtI6J8BQPA5q65gDQJJifS3QRx0S6 qaRFhTrhVj01e10eDhlBLkqfXJUhhuGqBopbjqLHtLHJZr8m0M2lEsiL1WFLv1BsITv5 oI7aN3lnq6Jrpr30uLyqwxjxMX0dmOf/6lhsESRN7VEQK1z9/t8ZLEO9wFFQm8YT/ZqX QjXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=organization: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=L/wVbVlQ4wEJNzZOzNf+dGjZ8JXDK2cQqIBafujPBwA=; fh=oWFj1HPwiu9zJJ1lym9G4qUj25jFSQwP9xY3cFZv6o8=; b=Zrrc9ycThdwY/kNx5PoEOTVBUJRLw8XnDqBWhE7h0IwSBM25ICvt6WfKjz6wgIc3g0 tKRZqfZOYazIg/XeVsyE/+wLi60uxGR8I8QTCiVwJUkgyVnRdDhYmvgfYUXcItrKO22+ Gs5nHU0DntcHuLPVC+lchZGsIbTUKbaIMimdtiRhtkv8XfbO0IN30z26njsHX+GlTYFG kkyFiW8zy+RGcNhs1haUg6ZzpaTwNkTOIeMXKWgaIGsM/RMIYgEJcXmn018InfFVsQ+8 7krP32c+e77DdoRdNpIMtktp4XkwI4A0auUDpIyqWBDS+0vE0/U6sSgaUFyhebnomESq CpJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MQn9GWxH; spf=pass (google.com: domain of linux-kernel+bounces-7173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e6-20020a654786000000b005c660ba30a7si21250563pgs.512.2023.12.20.07.44.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 07:44:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MQn9GWxH; spf=pass (google.com: domain of linux-kernel+bounces-7173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7D9C528A75F for ; Wed, 20 Dec 2023 15:34:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4019405CB; Wed, 20 Dec 2023 15:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MQn9GWxH" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 614133FB03; Wed, 20 Dec 2023 15:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703086476; x=1734622476; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=MCpjHy60vOZcPxidi339EczwHIe1GscXSj0PrPScous=; b=MQn9GWxH88N5mBhGGCicBeTWvYlTtt2CQxecuIPNEJjtBcfGNJTF+dDS za9WxD7qvJr0vatwH5nDrzmU75mSexXgH5Qrc4vjTDokiJx4GYioCOID/ SUfg8zsmaTaB+cOy3Ox4kwPpF+BdY+0CJECcqW6QEwpjy2OV7nWLE3M/O Muuxy3lnAJ1XwGesr7/MOnN67YBRtgXYazaujVPgmbCJDx//OCjlOw0As PjJ+tdA8lP7ihhZAZhEGNQf1DZaDWGcv6Tmh0Z29RkeAdml7h5L38QRaP haUwlzseISZjgKEU4HBrHubj5PuwPQMC1t8iaov6JICftxLgffs6fao/v Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="2921206" X-IronPort-AV: E=Sophos;i="6.04,291,1695711600"; d="scan'208";a="2921206" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2023 07:34:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10930"; a="810636058" X-IronPort-AV: E=Sophos;i="6.04,291,1695711600"; d="scan'208";a="810636058" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga001.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Dec 2023 07:34:32 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1rFyab-00000007aYe-0DyS; Wed, 20 Dec 2023 17:34:29 +0200 Date: Wed, 20 Dec 2023 17:34:28 +0200 From: Andy Shevchenko To: Hugo Villeneuve Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, jringle@gridpoint.com, kubakici@wp.pl, phil@raspberrypi.org, bo.svangard@embeddedart.se, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Hugo Villeneuve , stable@vger.kernel.org Subject: Re: [PATCH 01/18] serial: sc16is7xx: fix segfault when removing driver Message-ID: References: <20231219171903.3530985-1-hugo@hugovil.com> <20231219171903.3530985-2-hugo@hugovil.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: <20231219171903.3530985-2-hugo@hugovil.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Tue, Dec 19, 2023 at 12:18:45PM -0500, Hugo Villeneuve wrote: > From: Hugo Villeneuve > > If a problem with a device occurs during probing, and we subsequently > try to remove the driver, we get the following error: > > $ rmmod sc16is7xx > [ 62.783166] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000040 > [ 62.994226] Call trace: > [ 62.996672] serial_core_unregister_port+0x58/0x2b0 > [ 63.001558] serial_ctrl_unregister_port+0x18/0x30 > [ 63.006354] uart_remove_one_port+0x18/0x30 > [ 63.010542] sc16is7xx_spi_remove+0xc0/0x190 [sc16is7xx] > Segmentation fault > > Tested on a custom board with two SC16IS742 ICs, and by simulating a fault > when probing channel (port) B of the second device. > > The reason is that uart_remove_one_port() has already been called during > probe in the out_ports: error path, and is called again in > sc16is7xx_remove(). > > Fix the problem by clearing the device drvdata in probe error path to > indicate that all resources have been deallocated. And only deallocate > resources in sc16is7xx_remove() if device drvdata is non-null. ... > + dev_set_drvdata(dev, NULL); I believe this is wrong approach to fix the issue as this one is prone to be cleaned up in the future as we don't do this call explicitly for the past ~15 years. -- With Best Regards, Andy Shevchenko