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 3C012242D60; Mon, 23 Mar 2026 15:16:10 +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=1774278971; cv=none; b=cLIEyDP8SsLCbG5O32tL6uUcleSiETEe0GeIC88vw3bwbBUWzoTcSL7k0DeH+NaGLyv7KG2abuevDjYMtn0CXNdPjo5Cff0+XRyAkBusXzEPxyTZBwtwNLMvOKFFCpvXTDzHd4JVrP+2OyIJtZ9UUZfA/yvdUkWob90WlZJY5fY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278971; c=relaxed/simple; bh=sPlhitbKlewSo9EY9TCh1XIllx2Jx0BhUyjNH2idlFI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VXt2htltDyZ5hIwBDBgnAgLBPI6E9l7r9dQMdQaNLN936ev+GhBXvQ7436J5RjImUHSPK2cYyEHPuU4CdcB+nDIsUszGUHJ0eouOD8v6lPgjJUxSQ/A4resfDcBejVVypIg4MPNvHxg4PORM1vl/brBRut02PPInwKHK5z+u6pg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N53fvT7E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="N53fvT7E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62D5EC4CEF7; Mon, 23 Mar 2026 15:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774278970; bh=sPlhitbKlewSo9EY9TCh1XIllx2Jx0BhUyjNH2idlFI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N53fvT7EFhIHOPfJBCG4nQz//FjfRM7z8iDgritxxMnPnWuMsh9NfFZp4gnowG+c/ oHYONs7YVaUX5SVLupLzq93pSuZhHXg3lAh7bj9IUr/q9N/dVjljAEsg5uD6uOOkMv bW9GePaCUXkFpzHF0dv8O80fQNly2h5oK2FufEUo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Jander , Johan Hovold , Mark Brown Subject: [PATCH 6.6 478/567] spi: fix statistics allocation Date: Mon, 23 Mar 2026 14:46:38 +0100 Message-ID: <20260323134545.806472322@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134533.749096647@linuxfoundation.org> References: <20260323134533.749096647@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit dee0774bbb2abb172e9069ce5ffef579b12b3ae9 upstream. The controller per-cpu statistics is not allocated until after the controller has been registered with driver core, which leaves a window where accessing the sysfs attributes can trigger a NULL-pointer dereference. Fix this by moving the statistics allocation to controller allocation while tying its lifetime to that of the controller (rather than using implicit devres). Fixes: 6598b91b5ac3 ("spi: spi.c: Convert statistics to per-cpu u64_stats_t") Cc: stable@vger.kernel.org # 6.0 Cc: David Jander Signed-off-by: Johan Hovold Link: https://patch.msgid.link/20260312151817.32100-3-johan@kernel.org Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2777,6 +2777,8 @@ static void spi_controller_release(struc struct spi_controller *ctlr; ctlr = container_of(dev, struct spi_controller, dev); + + free_percpu(ctlr->pcpu_statistics); kfree(ctlr); } @@ -2928,6 +2930,12 @@ struct spi_controller *__spi_alloc_contr if (!ctlr) return NULL; + ctlr->pcpu_statistics = spi_alloc_pcpu_stats(NULL); + if (!ctlr->pcpu_statistics) { + kfree(ctlr); + return NULL; + } + device_initialize(&ctlr->dev); INIT_LIST_HEAD(&ctlr->queue); spin_lock_init(&ctlr->queue_lock); @@ -3216,13 +3224,6 @@ int spi_register_controller(struct spi_c if (status) goto del_ctrl; } - /* Add statistics */ - ctlr->pcpu_statistics = spi_alloc_pcpu_stats(dev); - if (!ctlr->pcpu_statistics) { - dev_err(dev, "Error allocating per-cpu statistics\n"); - status = -ENOMEM; - goto destroy_queue; - } mutex_lock(&board_lock); list_add_tail(&ctlr->list, &spi_controller_list); @@ -3235,8 +3236,6 @@ int spi_register_controller(struct spi_c acpi_register_spi_devices(ctlr); return status; -destroy_queue: - spi_destroy_queue(ctlr); del_ctrl: device_del(&ctlr->dev); free_bus_id: