From patchwork Fri Feb 10 20:51:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 653090 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B333AC05027 for ; Fri, 10 Feb 2023 20:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233904AbjBJUwc (ORCPT ); Fri, 10 Feb 2023 15:52:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233911AbjBJUw2 (ORCPT ); Fri, 10 Feb 2023 15:52:28 -0500 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F306025BA7 for ; Fri, 10 Feb 2023 12:52:27 -0800 (PST) Received: by mail-pl1-f169.google.com with SMTP id b5so7772577plz.5 for ; Fri, 10 Feb 2023 12:52:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xvAIWAxilX42GnQTgU1rO5h0Pxr8qRH2gVWXjZtbVtg=; b=0MqrJHZJ2r6yvmvFiszk8o08lN9jQb5RhJvIIYluHt/wqtAMzpiGt8tAaE/tZ6d7D/ mOnvnGzq6zc3nGcYVe1y/NvssDAf/kXU2z0IjjVYR/QJqpngoo2YWu3Mm7GKhotzzQ4l pYF76RIGC6n3CiORny8htBvpDBaWdpeS084eUXHVE/7BMpQntqrdEfSLq1CWQXhR1Ta9 2C3crDDOjaiP1sT0n9SQSbKFFjyOg+itTYkDGQOi+ZOgRXxd8SeHJ5Z2DtfkStF0XTpU J3rpQpobeKQDN126i5VfiFBJbgXkMKZxd1sUxtNEBd5UOCqGMDgm38vcWk7AD9LdfuO/ fefA== X-Gm-Message-State: AO0yUKU4KuQSmI0mxXOeses7KxV9P26fjZLtJO8JmTUneoLCqx24H7Hm lBExZapBDUG7twnFAqYqF9M= X-Google-Smtp-Source: AK7set+oKy/pFe336Wv4LBUNSU6XeeRX75FGDVqOqLCyFK8Hrwn20wej1A0XqnWvlzDQb40VMkZB0w== X-Received: by 2002:a17:902:e0cb:b0:19a:7622:23e4 with SMTP id e11-20020a170902e0cb00b0019a762223e4mr2087695pla.66.1676062347404; Fri, 10 Feb 2023 12:52:27 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a834:2664:42:db8b]) by smtp.gmail.com with ESMTPSA id jm13-20020a17090304cd00b001948ff5cc32sm3745752plb.215.2023.02.10.12.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 12:52:26 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Avri Altman , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , "James E.J. Bottomley" , Lee Duncan , Sagi Grimberg , Johannes Thumshirn Subject: [PATCH 1/2] scsi: core: Fix a source code comment Date: Fri, 10 Feb 2023 12:51:59 -0800 Message-Id: <20230210205200.36973-2-bvanassche@acm.org> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog In-Reply-To: <20230210205200.36973-1-bvanassche@acm.org> References: <20230210205200.36973-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Fix a reference in a source code comment to the scsi_remove_host() function. Fixes: b49493f99690 ("Fix a memory leak in scsi_host_dev_release()") Signed-off-by: Bart Van Assche --- drivers/scsi/hosts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index 12346e2297fd..b28375f9e019 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -356,7 +356,7 @@ static void scsi_host_dev_release(struct device *dev) /* * Free the shost_dev device name here if scsi_host_alloc() * and scsi_host_put() have been called but neither - * scsi_host_add() nor scsi_host_remove() has been called. + * scsi_host_add() nor scsi_remove_host() has been called. * This avoids that the memory allocated for the shost_dev * name is leaked. */ From patchwork Fri Feb 10 20:52:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 652634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EC94C636D4 for ; Fri, 10 Feb 2023 20:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233903AbjBJUwd (ORCPT ); Fri, 10 Feb 2023 15:52:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233901AbjBJUwb (ORCPT ); Fri, 10 Feb 2023 15:52:31 -0500 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 179485FE5; Fri, 10 Feb 2023 12:52:30 -0800 (PST) Received: by mail-pj1-f52.google.com with SMTP id pj3so6510051pjb.1; Fri, 10 Feb 2023 12:52:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/A/j3sjHfT49Ed2WzZTVw+auEmLb+Wp+YpWzo2DKZ4M=; b=PzjT7KwpKP89ad7bXellHPnDMP9hB0J2rACQ3IJFGpSnmrJ5MjFMAnms4edrKoU77U mCuiEb0H7lOC1L4JPLOWvxbgPv6px0kQhrhTtv+0LKC7w6iNGuEYlecA3m0mMEyKdNuI 77FviT8tl86I5JhfnilgoFB3LtR9PZC5B1R7GRDjTlQTS9nD5o29Ui0sPmKLGFtqB53R 5Nz9mlwtiOOJ03qmgFnR2LInJU51xiJ6es2VgKLjsKaqFs/IvCaOCF+ZTiXUmxUPWX+Z VWUK8cbyiugfaSPcP5rEXKYzZdoNmLO4nibukm2zXHQqmYmu0LQ0iafKa4jyp2jQNmBm /cPA== X-Gm-Message-State: AO0yUKUynt7KrJnwLDQGZwT2+Uy0MBoOWEvEnvGdOf+BtNI2Fy7kSpKg SpfDo9+EUPjEdew30W+aYhw= X-Google-Smtp-Source: AK7set/bUnEGLJr8I3LA464GRnFQyaf8QAnHqBPRXHovf1hjj3tPxON3Yud+X4Q8Axnvqmt1SIEu9g== X-Received: by 2002:a17:902:d4cc:b0:198:9bf8:298e with SMTP id o12-20020a170902d4cc00b001989bf8298emr17947174plg.60.1676062349284; Fri, 10 Feb 2023 12:52:29 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:a834:2664:42:db8b]) by smtp.gmail.com with ESMTPSA id jm13-20020a17090304cd00b001948ff5cc32sm3745752plb.215.2023.02.10.12.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 12:52:28 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , Avri Altman , Adrian Hunter , linux-scsi@vger.kernel.org, Bart Van Assche , Yi Zhang , Alan Stern , stable@vger.kernel.org, "James E.J. Bottomley" Subject: [PATCH 2/2] scsi: core: Remove the /proc/scsi/${proc_name} directory earlier Date: Fri, 10 Feb 2023 12:52:00 -0800 Message-Id: <20230210205200.36973-3-bvanassche@acm.org> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog In-Reply-To: <20230210205200.36973-1-bvanassche@acm.org> References: <20230210205200.36973-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Remove the /proc/scsi/${proc_name} directory earlier to fix a race condition between unloading and reloading kernel modules. This patch fixes a bug introduced in 2009 by patch "[SCSI] fix /proc memory leak in the SCSI core". This patch fixes the following kernel warning: proc_dir_entry 'scsi/scsi_debug' already registered WARNING: CPU: 19 PID: 27986 at fs/proc/generic.c:376 proc_register+0x27d/0x2e0 Call Trace: proc_mkdir+0xb5/0xe0 scsi_proc_hostdir_add+0xb5/0x170 scsi_host_alloc+0x683/0x6c0 sdebug_driver_probe+0x6b/0x2d0 [scsi_debug] really_probe+0x159/0x540 __driver_probe_device+0xdc/0x230 driver_probe_device+0x4f/0x120 __device_attach_driver+0xef/0x180 bus_for_each_drv+0xe5/0x130 __device_attach+0x127/0x290 device_initial_probe+0x17/0x20 bus_probe_device+0x110/0x130 device_add+0x673/0xc80 device_register+0x1e/0x30 sdebug_add_host_helper+0x1a7/0x3b0 [scsi_debug] scsi_debug_init+0x64f/0x1000 [scsi_debug] do_one_initcall+0xd7/0x470 do_init_module+0xe7/0x330 load_module+0x122a/0x12c0 __do_sys_finit_module+0x124/0x1a0 __x64_sys_finit_module+0x46/0x50 do_syscall_64+0x38/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0 Reported-by: Yi Zhang Cc: Alan Stern Cc: Yi Zhang Cc: stable@vger.kernel.org Signed-off-by: Bart Van Assche --- drivers/scsi/hosts.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c index b28375f9e019..f7f62e56afca 100644 --- a/drivers/scsi/hosts.c +++ b/drivers/scsi/hosts.c @@ -181,6 +181,7 @@ void scsi_remove_host(struct Scsi_Host *shost) scsi_forget_host(shost); mutex_unlock(&shost->scan_mutex); scsi_proc_host_rm(shost); + scsi_proc_hostdir_rm(shost->hostt); /* * New SCSI devices cannot be attached anymore because of the SCSI host @@ -340,6 +341,7 @@ static void scsi_host_dev_release(struct device *dev) struct Scsi_Host *shost = dev_to_shost(dev); struct device *parent = dev->parent; + /* In case scsi_remove_host() has not been called. */ scsi_proc_hostdir_rm(shost->hostt); /* Wait for functions invoked through call_rcu(&scmd->rcu, ...) */