From patchwork Wed Jun 26 18:00:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713212 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 6EEA219004C; Wed, 26 Jun 2024 18:01:00 +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=1719424860; cv=none; b=tOkLX9wwDesJKG9Ily5J9s8KcEaps0tQih+qTXLdACW8OQkLUJaLvOgWS4gNK5jwxrfGNwAZ3O7U6JXFARLizu5Ot4Il3aMrLN2b5Fi6lR0PatcpOJm3zDijMovqv2bK8fartXIbk6bilZdK0zSLeUi3c9k66x/M/SftUq6ivQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424860; c=relaxed/simple; bh=jZWsIbqDMulmqEcgw1nml3QjMymfnv611xCdyYVDH4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mkD0ANe6Wr/OTDUwvaPgOC5h70zTnxyokgQk9gfITUBb2QcuIo8laX7sq8DR2PficBUq5TrN5a/fdWxdiIS7fnYUQVvhk4pejGJlAX+LOKwszJmbduEqsZshlySqcIlQ+nGDRgsyjk6K8bqlDafJnBscwdv0utCYtOlDBA8OyS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uEA9sFdY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uEA9sFdY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB4D1C4AF09; Wed, 26 Jun 2024 18:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424860; bh=jZWsIbqDMulmqEcgw1nml3QjMymfnv611xCdyYVDH4s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uEA9sFdYBmRaE5d8r3Ud0/u0m58zdNMafqHaGqOj3ltOrtkgY3Tr2wiJ8LuNJFTbQ cV7Z/Y8AHNvtbP5+BNf8BXvtgCJAvKNN12VurpoqZeQXqR4w4w9c5Bh6HCyzIIiGFW 4ZDuNor8hSgrNfRbQ5p5I0oMh99310ScVvv9hotxoIavE11OfTe96G/ubSuDGPPERX ljdWwOZ2kvbx/Cr5yJMHTFkV8FSXPeG9xFScnxyO96d7HZfDhkVnP8OAseg9r02hUY Zx4NruTg2SHVKqHTTxnhU35Ih8dGr7FCq4yEdIdvTmKm/LILDEnhwulNL6BH65ihRB abvlXeytGNGTw== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel , Tejun Heo , Jeff Garzik Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , stable@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH v2 01/13] ata: libata-core: Fix null pointer dereference on error Date: Wed, 26 Jun 2024 20:00:31 +0200 Message-ID: <20240626180031.4050226-16-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2558; i=cassel@kernel.org; h=from:subject; bh=jZWsIbqDMulmqEcgw1nml3QjMymfnv611xCdyYVDH4s=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwu2/Hw1pCrS6JLc5RL50rdiCI1L827cufHeh1G9t4 XyhZh+djlIWBjEuBlkxRRbfHy77i7vdpxxXvGMDM4eVCWQIAxenAEzEvIWRYapRj3eu25Ws80sn 8a9es1yl/lCLT4BsHcPXiXNb1+TJn2dkuMl69lleAcupM/wiR6Pt2wQ81VmUO69dVTxw9PSrWRO zmQE= X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA If the ata_port_alloc() call in ata_host_alloc() fails, ata_host_release() will get called. However, the code in ata_host_release() tries to free ata_port struct members unconditionally, which can lead to the following: BUG: unable to handle page fault for address: 0000000000003990 PGD 0 P4D 0 Oops: Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 10 PID: 594 Comm: (udev-worker) Not tainted 6.10.0-rc5 #44 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014 RIP: 0010:ata_host_release.cold+0x2f/0x6e [libata] Code: e4 4d 63 f4 44 89 e2 48 c7 c6 90 ad 32 c0 48 c7 c7 d0 70 33 c0 49 83 c6 0e 41 RSP: 0018:ffffc90000ebb968 EFLAGS: 00010246 RAX: 0000000000000041 RBX: ffff88810fb52e78 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffff88813b3218c0 RDI: ffff88813b3218c0 RBP: ffff88810fb52e40 R08: 0000000000000000 R09: 6c65725f74736f68 R10: ffffc90000ebb738 R11: 73692033203a746e R12: 0000000000000004 R13: 0000000000000000 R14: 0000000000000011 R15: 0000000000000006 FS: 00007f6cc55b9980(0000) GS:ffff88813b300000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000003990 CR3: 00000001122a2000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: ? __die_body.cold+0x19/0x27 ? page_fault_oops+0x15a/0x2f0 ? exc_page_fault+0x7e/0x180 ? asm_exc_page_fault+0x26/0x30 ? ata_host_release.cold+0x2f/0x6e [libata] ? ata_host_release.cold+0x2f/0x6e [libata] release_nodes+0x35/0xb0 devres_release_group+0x113/0x140 ata_host_alloc+0xed/0x120 [libata] ata_host_alloc_pinfo+0x14/0xa0 [libata] ahci_init_one+0x6c9/0xd20 [ahci] Do not access ata_port struct members unconditionally. Fixes: 633273a3ed1c ("libata-pmp: hook PMP support and enable it") Cc: stable@vger.kernel.org Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index e1bf8a19b3c8..88e32f638f33 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5518,10 +5518,12 @@ static void ata_host_release(struct kref *kref) for (i = 0; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; - kfree(ap->pmp_link); - kfree(ap->slave_link); - kfree(ap->ncq_sense_buf); - kfree(ap); + if (ap) { + kfree(ap->pmp_link); + kfree(ap->slave_link); + kfree(ap->ncq_sense_buf); + kfree(ap); + } host->ports[i] = NULL; } kfree(host); From patchwork Wed Jun 26 18:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713213 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 12A4118F2F0; Wed, 26 Jun 2024 18:01:07 +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=1719424867; cv=none; b=To08S9AU861tvJe9kCvds3Z41ge39GGHX0Mmi7wo+mXGMBE4U5vv2sdG0tNX5s/u+6ic5ILX/zlGoAEHOjf5/QFqoj+nlFXqIEG+K9QLwCrKTLDBzYbOaSAwrQvZlpXyHqxvIX+ywtHk8rxdAaiYHPKr6YV5P/cNPAl0jS95VRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424867; c=relaxed/simple; bh=o80Xm0+POlm2k0LTk7Efl4HCmFTOVufSY3+zwEc/JJM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kIoAffF06ea3Hq8WU8cV9c8tsnNAK4eZNndeBuBhqVxl+VlqoED3tGhFBp8/+Dhd+RQ966DowqfUjvR0vjoAEszgHc1IWPcVujs5sSkFOKAcVg9B9LH3RSH6jZjBQMhE6SOvgD/PuYZS02dStndKjpkPvOtsf6zAKoUTHlwXVgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cCv20OEE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cCv20OEE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76B1BC32789; Wed, 26 Jun 2024 18:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424866; bh=o80Xm0+POlm2k0LTk7Efl4HCmFTOVufSY3+zwEc/JJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cCv20OEEzZHPAp63+RtlGVpRsabW+M0wIMqtIwBYAmnVw9M/Te1oBTBcF4P3xLmNQ FasW6Kw7qBvHZyyGkV3ZcGjygzBJXTLN6HhSnS02WC5jHRgwMPlAjBKrvmkgJJPF7n rs1qfQ+TA/t1P1EUEeijSA6W17yRQY4TFWKTWAPtT3GUi3a6qHeGMgRToHPDbVbEXD WVWrvaYyavOw63WeCfGzI1fVDA3mJYZDSiFIPkQNPwAkcLdZ7pyq+oMNUpAoNOBOVr O+jM8LXgIi9MjFYuieHhtmGPy0C8Y0l7pisICL9MPSkw1rw5DSJ0dSrRX+zQ4xLVvg UqBjiW1+QDQfg== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel , Colin Ian King , Tejun Heo Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , stable@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH v2 02/13] ata: libata-core: Fix double free on error Date: Wed, 26 Jun 2024 20:00:32 +0200 Message-ID: <20240626180031.4050226-17-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2851; i=cassel@kernel.org; h=from:subject; bh=o80Xm0+POlm2k0LTk7Efl4HCmFTOVufSY3+zwEc/JJM=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwu1/MPSax+ou84lZYH/3A4/szQh2PouW+V5phVuE9 9hvr+/vKGVhEONikBVTZPH94bK/uNt9ynHFOzYwc1iZQIYwcHEKwERcPBj+B/JferJq1gGD12eL o9rmXw0PedAsIas4V/tDMoO9Vt3RKIZ/phkv2o+Zzvv8dBNvabXR7D+xb2+uC178XJwh/bVP266 5nAA= X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA If e.g. the ata_port_alloc() call in ata_host_alloc() fails, we will jump to the err_out label, which will call devres_release_group(). devres_release_group() will trigger a call to ata_host_release(). ata_host_release() calls kfree(host), so executing the kfree(host) in ata_host_alloc() will lead to a double free: kernel BUG at mm/slub.c:553! Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 11 PID: 599 Comm: (udev-worker) Not tainted 6.10.0-rc5 #47 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014 RIP: 0010:kfree+0x2cf/0x2f0 Code: 5d 41 5e 41 5f 5d e9 80 d6 ff ff 4d 89 f1 41 b8 01 00 00 00 48 89 d9 48 89 da RSP: 0018:ffffc90000f377f0 EFLAGS: 00010246 RAX: ffff888112b1f2c0 RBX: ffff888112b1f2c0 RCX: ffff888112b1f320 RDX: 000000000000400b RSI: ffffffffc02c9de5 RDI: ffff888112b1f2c0 RBP: ffffc90000f37830 R08: 0000000000000000 R09: 0000000000000000 R10: ffffc90000f37610 R11: 617461203a736b6e R12: ffffea00044ac780 R13: ffff888100046400 R14: ffffffffc02c9de5 R15: 0000000000000006 FS: 00007f2f1cabe980(0000) GS:ffff88813b380000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f2f1c3acf75 CR3: 0000000111724000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: ? __die_body.cold+0x19/0x27 ? die+0x2e/0x50 ? do_trap+0xca/0x110 ? do_error_trap+0x6a/0x90 ? kfree+0x2cf/0x2f0 ? exc_invalid_op+0x50/0x70 ? kfree+0x2cf/0x2f0 ? asm_exc_invalid_op+0x1a/0x20 ? ata_host_alloc+0xf5/0x120 [libata] ? ata_host_alloc+0xf5/0x120 [libata] ? kfree+0x2cf/0x2f0 ata_host_alloc+0xf5/0x120 [libata] ata_host_alloc_pinfo+0x14/0xa0 [libata] ahci_init_one+0x6c9/0xd20 [ahci] Ensure that we will not call kfree(host) twice, by performing the kfree() only if the devres_open_group() call failed. Fixes: dafd6c496381 ("libata: ensure host is free'd on error exit paths") Cc: stable@vger.kernel.org Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 88e32f638f33..c916cbe3e099 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5573,8 +5573,10 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) if (!host) return NULL; - if (!devres_open_group(dev, NULL, GFP_KERNEL)) - goto err_free; + if (!devres_open_group(dev, NULL, GFP_KERNEL)) { + kfree(host); + return NULL; + } dr = devres_alloc(ata_devres_release, 0, GFP_KERNEL); if (!dr) @@ -5606,8 +5608,6 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) err_out: devres_release_group(dev, NULL); - err_free: - kfree(host); return NULL; } EXPORT_SYMBOL_GPL(ata_host_alloc); From patchwork Wed Jun 26 18:00:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713214 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 09B5118FDBF; Wed, 26 Jun 2024 18:01:13 +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=1719424874; cv=none; b=ICzr3MZedicOhuuOoBgLRSJI0JVE8F1UDOBJvpunfmw3EZEKLjulPzDhpmc1OnSQFU5Bzm9xU0ykxynCQBdgLY0W2MwwCtVf00j5lcd0oFrRlPzPdJdgYOO8R0dki808E7bbfnfljFJGK+oddyauyZIyuGG52VNGPqdYrgV6uIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424874; c=relaxed/simple; bh=xH/IMmvYQ1NPWOkGIYV4wiFxbR2lUHnL00MHbR1iKbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=obd+lPFbtAggBF+1m0E+HLrYesFeVZ6+4rCefJfga8uBoXX3o8LrF3rs4AkMowEYhJ7cqcyXtBngDMGw3TXIbAE+vPQs+SATTdmDGBc45albCUrB/D8W//cfQJIF/g45bJIFHouZ1AoM0iGGkkcW0NA74G75y/xpVpH69U0luUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cqe23CKT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cqe23CKT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20AF2C4AF07; Wed, 26 Jun 2024 18:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424873; bh=xH/IMmvYQ1NPWOkGIYV4wiFxbR2lUHnL00MHbR1iKbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cqe23CKT1y+EabZxtFCHH4m6fFIp2ZhLN8kTej+ejIZDzJrSt9ERgq8rkym1iqiEr l6AykZhKK2AJLqv7lgxSUfnYJaQ0lRBYSv+IMfRJVHPFUjg5BQUO9BG8ydVGksa+XY gHW5ebDhw96TvCJaMMoJME5A/lSvpdHKqSNBbUo/2Zx4I088TUHLqQ6Nn4frJ6wohV qUos9iIFzDqB3COcxYZrL4FAIChDje9C32+c9dM+RLDPoKSRdnNHFQyWS9M1uHiAIT qiFnGn484apsLuIY9xXqcb53wUs9A+2ApPrDcRo4K1WztAioLA7kQx0iGXwDBQEOpC dCiLNLpRMmUHw== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel , Kai-Heng Feng , Jens Axboe Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , stable@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH v2 03/13] ata: ahci: Clean up sysfs file on error Date: Wed, 26 Jun 2024 20:00:33 +0200 Message-ID: <20240626180031.4050226-18-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2512; i=cassel@kernel.org; h=from:subject; bh=xH/IMmvYQ1NPWOkGIYV4wiFxbR2lUHnL00MHbR1iKbA=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwh1yNgYG99+PLpb/kXXt+cmSzZLf3NRfeAbm1AZ+C mo//npTRykLgxgXg6yYIovvD5f9xd3uU44r3rGBmcPKBDKEgYtTACZyRJyRYcJbP+8PB9ZOu7zR LWftww11H1gWTRO3Tj2h1BP44MOjsiqGf/Yd2Stu5pXdvWP1/5qIsdRiDasgi6Llv5L/6JsZHDh wmx8A X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA .probe() (ahci_init_one()) calls sysfs_add_file_to_group(), however, if probe() fails after this call, we currently never call sysfs_remove_file_from_group(). (The sysfs_remove_file_from_group() call in .remove() (ahci_remove_one()) does not help, as .remove() is not called on .probe() error.) Thus, if probe() fails after the sysfs_add_file_to_group() call, we get: sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:04.0/remapped_nvme' CPU: 11 PID: 954 Comm: modprobe Not tainted 6.10.0-rc5 #43 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014 Call Trace: dump_stack_lvl+0x5d/0x80 sysfs_warn_dup.cold+0x17/0x23 sysfs_add_file_mode_ns+0x11a/0x130 sysfs_add_file_to_group+0x7e/0xc0 ahci_init_one+0x31f/0xd40 [ahci] Fixes: 894fba7f434a ("ata: ahci: Add sysfs attribute to show remapped NVMe device count") Cc: stable@vger.kernel.org Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/ahci.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 5eb38fbbbecd..fc6fd583faf8 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -1975,8 +1975,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map)); host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); - if (!host) - return -ENOMEM; + if (!host) { + rc = -ENOMEM; + goto err_rm_sysfs_file; + } host->private_data = hpriv; if (ahci_init_msi(pdev, n_ports, hpriv) < 0) { @@ -2031,11 +2033,11 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) /* initialize adapter */ rc = ahci_configure_dma_masks(pdev, hpriv); if (rc) - return rc; + goto err_rm_sysfs_file; rc = ahci_pci_reset_controller(host); if (rc) - return rc; + goto err_rm_sysfs_file; ahci_pci_init_controller(host); ahci_pci_print_info(host); @@ -2044,10 +2046,15 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) rc = ahci_host_activate(host, &ahci_sht); if (rc) - return rc; + goto err_rm_sysfs_file; pm_runtime_put_noidle(&pdev->dev); return 0; + +err_rm_sysfs_file: + sysfs_remove_file_from_group(&pdev->dev.kobj, + &dev_attr_remapped_nvme.attr, NULL); + return rc; } static void ahci_shutdown_one(struct pci_dev *pdev) From patchwork Wed Jun 26 18:00:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713215 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 C550415B55D; Wed, 26 Jun 2024 18:01:19 +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=1719424879; cv=none; b=iMFOA1uYpXStRytxFZtNLKdqJq1LF8awBrPNN4K16skXqHiu+v7qwu2denVNG3/FmlNc1fzPGmIs9xXcVSF36FTnEu3OJEfDHLHAFe3qD0RVMarymKFsP/OAbgZP6xf3jrsll3f9MXWlYOcUmRsBIIEh7pk4CMjee6k2C3E0VlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424879; c=relaxed/simple; bh=ZL1nwDzfI+ryUk6FQso2XK2cFPn6McHKtJqVFsUzmco=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=omz6tpohI5pJT7lUtaix0E53WxaxpfLzCoIkCMloAqLys5cshTJ+w4l1n8hVnNzaEW/oGmIApWM/wxcVJ0azenZQmHxsrk22etIP3J3sA+QNR8fZ4JcTQowkwp2l2r/aNfrXfgt4tfYmcP1fWMVFhl3bweliEoDe2Vs0bcSrKkY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YxT6rzRf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YxT6rzRf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23A2AC32782; Wed, 26 Jun 2024 18:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424879; bh=ZL1nwDzfI+ryUk6FQso2XK2cFPn6McHKtJqVFsUzmco=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YxT6rzRfjrk7P0pDEY07vpY/qNdPEKIAW8isEcJnrkQnrNiDlpyWsvy97PedEFeo6 T7IxHVEag1552dUY5/+aXqVHvyWevnepBIbTdILyvb42ur2V96RRdgtcpYJUW9LvNb nN8MxXkW4DPjNWgL1kNA48jTb3oht6LeWsisoJW5Wh2lDNI3c6lr1ZROJ6pFsPmnQx 5u6D+IZ6oLfn8YPtRzcVxS7uRWYNFWWzwcJ5EsgQ7JpkNp40pTlwCgoxiNaKwyothl +Re/X9uBOu5hIc73kO7JhksIY4FR9EoUXTcERJ3In7LiDCkFMNI+8A1VXBGeUWQAaS rzFbB/91b3tfg== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel , John Garry , Jason Yan , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH v2 04/13] ata,scsi: Remove useless wrappers ata_sas_tport_{add,delete}() Date: Wed, 26 Jun 2024 20:00:34 +0200 Message-ID: <20240626180031.4050226-19-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4300; i=cassel@kernel.org; h=from:subject; bh=ZL1nwDzfI+ryUk6FQso2XK2cFPn6McHKtJqVFsUzmco=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwh2iMiIVJ0Zx8qln53HP6ZA5uPRGytoLTMsVPk459 b9pXY94RykLgxgXg6yYIovvD5f9xd3uU44r3rGBmcPKBDKEgYtTACaiUcbwT/2FQ7mQ8KNzPvoJ fznnae7o33uWefaZI/s+PQkQ8A36sZPhv/ea1SphJnyKl5W7Jr08aL1P4opGiPS20CWOG+oOHly lxwAA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA Remove useless wrappers ata_sas_tport_add() and ata_sas_tport_delete(). Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-sata.c | 12 ------------ drivers/ata/libata-transport.c | 2 ++ drivers/ata/libata-transport.h | 3 --- drivers/scsi/libsas/sas_ata.c | 2 +- drivers/scsi/libsas/sas_discover.c | 2 +- include/linux/libata.h | 4 ++-- 6 files changed, 6 insertions(+), 19 deletions(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 9e047bf912b1..e7991595bfe5 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1241,18 +1241,6 @@ struct ata_port *ata_sas_port_alloc(struct ata_host *host, } EXPORT_SYMBOL_GPL(ata_sas_port_alloc); -int ata_sas_tport_add(struct device *parent, struct ata_port *ap) -{ - return ata_tport_add(parent, ap); -} -EXPORT_SYMBOL_GPL(ata_sas_tport_add); - -void ata_sas_tport_delete(struct ata_port *ap) -{ - ata_tport_delete(ap); -} -EXPORT_SYMBOL_GPL(ata_sas_tport_delete); - /** * ata_sas_device_configure - Default device_configure routine for libata * devices diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c index 3e49a877500e..d24f201c0ab2 100644 --- a/drivers/ata/libata-transport.c +++ b/drivers/ata/libata-transport.c @@ -265,6 +265,7 @@ void ata_tport_delete(struct ata_port *ap) transport_destroy_device(dev); put_device(dev); } +EXPORT_SYMBOL_GPL(ata_tport_delete); static const struct device_type ata_port_sas_type = { .name = ATA_PORT_TYPE_NAME, @@ -329,6 +330,7 @@ int ata_tport_add(struct device *parent, put_device(dev); return error; } +EXPORT_SYMBOL_GPL(ata_tport_add); /** * ata_port_classify - determine device type based on ATA-spec signature diff --git a/drivers/ata/libata-transport.h b/drivers/ata/libata-transport.h index 08a57fb9dc61..50cd2cbe8eea 100644 --- a/drivers/ata/libata-transport.h +++ b/drivers/ata/libata-transport.h @@ -8,9 +8,6 @@ extern struct scsi_transport_template *ata_scsi_transport_template; int ata_tlink_add(struct ata_link *link); void ata_tlink_delete(struct ata_link *link); -int ata_tport_add(struct device *parent, struct ata_port *ap); -void ata_tport_delete(struct ata_port *ap); - struct scsi_transport_template *ata_attach_transport(void); void ata_release_transport(struct scsi_transport_template *t); diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index 4c69fc63c119..1c2400c96ebd 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -608,7 +608,7 @@ int sas_ata_init(struct domain_device *found_dev) ap->cbl = ATA_CBL_SATA; ap->scsi_host = shost; - rc = ata_sas_tport_add(ata_host->dev, ap); + rc = ata_tport_add(ata_host->dev, ap); if (rc) goto destroy_port; diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c index 8fb7c41c0962..6e01ddec10c9 100644 --- a/drivers/scsi/libsas/sas_discover.c +++ b/drivers/scsi/libsas/sas_discover.c @@ -300,7 +300,7 @@ void sas_free_device(struct kref *kref) kfree(dev->ex_dev.ex_phy); if (dev_is_sata(dev) && dev->sata_dev.ap) { - ata_sas_tport_delete(dev->sata_dev.ap); + ata_tport_delete(dev->sata_dev.ap); kfree(dev->sata_dev.ap); ata_host_put(dev->sata_dev.ata_host); dev->sata_dev.ata_host = NULL; diff --git a/include/linux/libata.h b/include/linux/libata.h index 13fb41d25da6..581e166615fa 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1249,8 +1249,8 @@ extern int ata_slave_link_init(struct ata_port *ap); extern struct ata_port *ata_sas_port_alloc(struct ata_host *, struct ata_port_info *, struct Scsi_Host *); extern void ata_port_probe(struct ata_port *ap); -extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap); -extern void ata_sas_tport_delete(struct ata_port *ap); +extern int ata_tport_add(struct device *parent, struct ata_port *ap); +extern void ata_tport_delete(struct ata_port *ap); int ata_sas_device_configure(struct scsi_device *sdev, struct queue_limits *lim, struct ata_port *ap); extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap); From patchwork Wed Jun 26 18:00:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713216 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 5731D6E613; Wed, 26 Jun 2024 18:01:25 +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=1719424885; cv=none; b=kTfR1Iu66fV8RhyaH13rgn0Gx5aoR0tKlU7VzI9ndOf0ZWw2ZVPxMg0FAyEu4/4ScMV3q31/lmNBhjAB3xSn9x/y9Qgdvw+RxOBaApO7QlglpPzOM9/roEdrVkV4WE57I8FFG8Q7zobX2Q/Nzpf0VFZfsfVJEUsyjDPwPe3rA1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424885; c=relaxed/simple; bh=eW+RWOtkOzS/Mw/Oj7hVhpP1gSVa4ky/5MrpmPV8NF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XRVT7xKG/mpfInI+G3fIZDludU84d5PMBxH8wsVizLss+EIWzcIUz0bOXyev46k5syPTZdknGlIwT9sZtIl7wuRyoed9C7/ip3euXrokHzDAEKQIRZRpmFCvyOdEH0l+jyKhLANyISys/GUhLi1nTT3UY0Ph+SUzYnsddczLet0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cgZ5UOqX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cgZ5UOqX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5F13C4AF09; Wed, 26 Jun 2024 18:01:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424884; bh=eW+RWOtkOzS/Mw/Oj7hVhpP1gSVa4ky/5MrpmPV8NF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cgZ5UOqX9C2sl/Tz8JwZxIpt/e2b2PC1gWqR34x/8UBdmEQ/GFJZ7RAdYggrvnS71 LNfv12YooqZ3SOskZwG/tISyTJkijk6aiXjI+J5OulFgCWyNLcdjbNLSP3sIZcjl9e WCUaLnrfhx+6csEhXTEAE9oUxaaFMqPATjZxvHdrK3+Up8M1DqrbrqGdcMWbgRWC7L jZBgXsmnDOLF9keB/v/81UZBfrPORNbZu40dLrUXJIqoM+TrKz1Yv2dDv8YQo8K7Qn rxxcHvOuiSqQRzb5yZD+b+ioSmXKUoD9yAXeLqPx9g5E8Gvx+rLPvykomJfqRrOnPL jIpbriVrb39hA== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel , John Garry , Jason Yan , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH v2 05/13] ata,scsi: libata-core: Add ata_port_free() Date: Wed, 26 Jun 2024 20:00:35 +0200 Message-ID: <20240626180031.4050226-20-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3228; i=cassel@kernel.org; h=from:subject; bh=eW+RWOtkOzS/Mw/Oj7hVhpP1gSVa4ky/5MrpmPV8NF0=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwh0bFvwMuxgWmfkjfkrP4Q2ruqLONKgsWLWp0Mvp9 I7n7iv6O0pZGMS4GGTFFFl8f7jsL+52n3Jc8Y4NzBxWJpAhDFycAjARowqG/9HJsxyU/EU51vFv FZHUU/jReGuWY2BzPf/pDvu+sLlPXzEy7GvdfP7Zuwf1va3/jrKLu1RPOOv13mZJ4buEF+5WzY5 djAA= X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA Add a function, ata_port_free(), that is used to free a ata_port. It makes sense to keep the code related to freeing a ata_port in its own function, which will also free all the struct members of struct ata_port. libsas is currently not freeing all the struct ata_port struct members, e.g. ncq_sense_buf for a driver supporting Command Duration Limits (CDL). Signed-off-by: Niklas Cassel --- drivers/ata/libata-core.c | 19 +++++++++++++------ drivers/scsi/libsas/sas_ata.c | 2 +- drivers/scsi/libsas/sas_discover.c | 2 +- include/linux/libata.h | 1 + 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index c916cbe3e099..591020ea8989 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5490,6 +5490,18 @@ struct ata_port *ata_port_alloc(struct ata_host *host) return ap; } +void ata_port_free(struct ata_port *ap) +{ + if (!ap) + return; + + kfree(ap->pmp_link); + kfree(ap->slave_link); + kfree(ap->ncq_sense_buf); + kfree(ap); +} +EXPORT_SYMBOL_GPL(ata_port_free); + static void ata_devres_release(struct device *gendev, void *res) { struct ata_host *host = dev_get_drvdata(gendev); @@ -5518,12 +5530,7 @@ static void ata_host_release(struct kref *kref) for (i = 0; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; - if (ap) { - kfree(ap->pmp_link); - kfree(ap->slave_link); - kfree(ap->ncq_sense_buf); - kfree(ap); - } + ata_port_free(ap); host->ports[i] = NULL; } kfree(host); diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index 1c2400c96ebd..e8987dce585f 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -618,7 +618,7 @@ int sas_ata_init(struct domain_device *found_dev) return 0; destroy_port: - kfree(ap); + ata_port_free(ap); free_host: ata_host_put(ata_host); return rc; diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c index 6e01ddec10c9..951bdc554a10 100644 --- a/drivers/scsi/libsas/sas_discover.c +++ b/drivers/scsi/libsas/sas_discover.c @@ -301,7 +301,7 @@ void sas_free_device(struct kref *kref) if (dev_is_sata(dev) && dev->sata_dev.ap) { ata_tport_delete(dev->sata_dev.ap); - kfree(dev->sata_dev.ap); + ata_port_free(dev->sata_dev.ap); ata_host_put(dev->sata_dev.ata_host); dev->sata_dev.ata_host = NULL; dev->sata_dev.ap = NULL; diff --git a/include/linux/libata.h b/include/linux/libata.h index 581e166615fa..586f0116d1d7 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1249,6 +1249,7 @@ extern int ata_slave_link_init(struct ata_port *ap); extern struct ata_port *ata_sas_port_alloc(struct ata_host *, struct ata_port_info *, struct Scsi_Host *); extern void ata_port_probe(struct ata_port *ap); +extern void ata_port_free(struct ata_port *ap); extern int ata_tport_add(struct device *parent, struct ata_port *ap); extern void ata_tport_delete(struct ata_port *ap); int ata_sas_device_configure(struct scsi_device *sdev, struct queue_limits *lim, From patchwork Wed Jun 26 18:00:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713217 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 74DC815B55D; Wed, 26 Jun 2024 18:01:30 +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=1719424890; cv=none; b=DC6z2nlXDTdZYUGzjebyPYFc9ExENqTtmdxLa2bq6WYdFrX9iwLRlzKSwrcEJk+EV31/clCTh4gdAQkpP067+JtUWlp5z2u53Y0dcnkZ0iKsU2JPf2WLcaaltgYMMuTNdWaCQYT1FWOhNTU4iRDTD94P/ROXbBpVVZFeHiZOm0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424890; c=relaxed/simple; bh=2SyEIZRwoD9Q+scRUl3XBQp6V3M4r5BLXo2ZgFirchI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gk3rbuFBpescrottkyHIbxIB+D9K39w3HAFuF+pFiBgpOMNlElHJJ/DpPce5+GEkgh2Vz8BOwmh0G9uSm8oEsu++Iz0mqyyCCyleNwyA4VSUsf9EcuRDRR8dDOxsSvxFjgPTFa8Of2y0ZIz/MReC98O4MMIv9vT8RHR0AV7H7FQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SvJCGxDZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SvJCGxDZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18D69C4AF0A; Wed, 26 Jun 2024 18:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424890; bh=2SyEIZRwoD9Q+scRUl3XBQp6V3M4r5BLXo2ZgFirchI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SvJCGxDZT3Vq8ZqjHfG8J0BCqjGkuUV3/QhyX7Qj0n8Min8ejVRyGmoH2s9x9RsC6 R2lRDOH4XEfZCuY96ABMTiuJYcr7iPr4LebgK3UB6f+RdTP6xWYKEavfxEUJLRFWyj XZznAvB8ezzuzsO8bD4A8U0hnsSLVcgHKRSHVIiUoaYO97d1h/QyuhQWMeyW6ESCM+ +m061ifVesLWmNcLF8k45S8zUi1RAZYLUdAeSG0taySVtZLy5Kb10bt9cjigl2XNn+ wc8DuTYjBWUYpLIzgl9CM9dMxlrcHCMwbDjV/t75e55oCaYUPUsnmWb3rDvC2aqge6 V0SAUr6MKJA+Q== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , linux-ide@vger.kernel.org Subject: [PATCH v2 06/13] ata: libata: Remove unused function declaration for ata_scsi_detect() Date: Wed, 26 Jun 2024 20:00:36 +0200 Message-ID: <20240626180031.4050226-21-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=820; i=cassel@kernel.org; h=from:subject; bh=2SyEIZRwoD9Q+scRUl3XBQp6V3M4r5BLXo2ZgFirchI=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwh1rJRxC54vredxMtboUeGnL7NdPO5vkcqp7C4O1b vJevryzo5SFQYyLQVZMkcX3h8v+4m73KccV79jAzGFlAhnCwMUpABPxncnwz+px9uPk1MbVp7Yu O88stvcLk4J3wt+I73J6i/pMJAPqShgZ3hXLxG5h933J/JNL5Mm8RWWN2rdCRQ6+tBDQuBcT7iX DCwA= X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA Remove unsed function declaration for ata_scsi_detect(). Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- include/linux/libata.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/linux/libata.h b/include/linux/libata.h index 586f0116d1d7..580971e11804 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1082,7 +1082,6 @@ extern int ata_host_activate(struct ata_host *host, int irq, const struct scsi_host_template *sht); extern void ata_host_detach(struct ata_host *host); extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *); -extern int ata_scsi_detect(struct scsi_host_template *sht); extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd, void __user *arg); #ifdef CONFIG_COMPAT From patchwork Wed Jun 26 18:00:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713218 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 E937B6E613; Wed, 26 Jun 2024 18:01:35 +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=1719424896; cv=none; b=tCDCtCsTxTj29MTF6/Hlv+ts7aZ9ppL+quE2gsO6kBPhx2uebuP3xttdWhgAdj1+mN05Br3v7weBVOtRncS49hdeIR6dh2kPeDLoR5gA77W6tRKuf+3EJ4xb9rf6Sl4L146r5WZ0Px1qTSMxjNR25ttCFJyh0xFwUguiLtnenqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424896; c=relaxed/simple; bh=ppedzp1AaxL9/kS2JLoS2AUa1W0Jtte4QmafLe6BgYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mL4eIL48c3Cqhh1z5j23Sjvh6WXPW2jjrLdKxF+vpCpx4RDpIEzW07HKTdjXiYW39EWEgCQYroZlUTdVPBeYJ1UJq9b/p/9ktienOKOgYbeLNU+Mo7DndZIx6eCZkh49ccSvt1RBHWv0oEBnEgJvsBMghs3EhN2/c6r/z7aF3sk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DjGcOOhw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DjGcOOhw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93EE0C32782; Wed, 26 Jun 2024 18:01:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424895; bh=ppedzp1AaxL9/kS2JLoS2AUa1W0Jtte4QmafLe6BgYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DjGcOOhwU1KXY/WbnVm86F2MDJBCxSesDNiMryscKQ0JW0nyioJX3xbYZimMY+abO 1r82hpbZlvs5VUYWPVxXcivjT7GP+BjEgyFW4dg1DVo+Wr82ZVDTpYFnesxPiWbxQ1 id6LyUSPfcc1EqQ8A7Vel4gotSI17l5XnGwkLEibbvbteaniIOZSuvLpAtxOHe75z1 WuvLd7zVYKKONfhjHVv6g1K7oMBzxcpK07UQVoRgSid9J9vKOpDOLEue3u9JVdJ4R6 UF+oK7Xun8vfU6qNmmKlWrSOpj5R/F+dccWgUof0ZB6e104mEYsnwIbwg6GaCMa2V6 wVyd9RquAfTmQ== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , linux-ide@vger.kernel.org Subject: [PATCH v2 07/13] ata: libata-core: Remove support for decreasing the number of ports Date: Wed, 26 Jun 2024 20:00:37 +0200 Message-ID: <20240626180031.4050226-22-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4496; i=cassel@kernel.org; h=from:subject; bh=ppedzp1AaxL9/kS2JLoS2AUa1W0Jtte4QmafLe6BgYU=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwp2OLlq7cR7jzdnsmmLrT9+KtTswQf+4x8Gt//tuR 7DK+rYpdZSyMIhxMciKKbL4/nDZX9ztPuW44h0bmDmsTCBDGLg4BWAiexkYGfY05UVeZWP7eP3X 3BaJrbd8tjsc38bpePapaLqN5M9ECS2G/4Vx99dU3Tpy1mhx/dSDbXXaTUvWL38et+Sa9MJNK47 LRjADAA== X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA Commit f31871951b38 ("libata: separate out ata_host_alloc() and ata_host_register()") added ata_host_alloc(), where the API allowed a LLD to overallocate the number of ports supplied to ata_host_alloc(), as long as the LLD decreased host->n_ports before calling ata_host_register(). However, this functionally has never ever been used by a single LLD. Because of the current API design, the assignment of ap->print_id is deferred until registration time, which is bad, because that means that the ata_port_*() print functions cannot be used by a LLD until after registration time, which means that a LLD is forced to use a print function that is non-port specific, even for a port specific error. Remove the support for decreasing the number of ports, such that it will be possible to assign ap->print_id earlier. Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal --- drivers/ata/libata-core.c | 24 ++++++++++-------------- include/linux/libata.h | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 591020ea8989..a213a9c0d0a5 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5550,24 +5550,19 @@ EXPORT_SYMBOL_GPL(ata_host_put); /** * ata_host_alloc - allocate and init basic ATA host resources * @dev: generic device this host is associated with - * @max_ports: maximum number of ATA ports associated with this host + * @n_ports: the number of ATA ports associated with this host * * Allocate and initialize basic ATA host resources. LLD calls * this function to allocate a host, initializes it fully and * attaches it using ata_host_register(). * - * @max_ports ports are allocated and host->n_ports is - * initialized to @max_ports. The caller is allowed to decrease - * host->n_ports before calling ata_host_register(). The unused - * ports will be automatically freed on registration. - * * RETURNS: * Allocate ATA host on success, NULL on failure. * * LOCKING: * Inherited from calling layer (may sleep). */ -struct ata_host *ata_host_alloc(struct device *dev, int max_ports) +struct ata_host *ata_host_alloc(struct device *dev, int n_ports) { struct ata_host *host; size_t sz; @@ -5575,7 +5570,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) void *dr; /* alloc a container for our list of ATA ports (buses) */ - sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *); + sz = sizeof(struct ata_host) + (n_ports + 1) * sizeof(void *); host = kzalloc(sz, GFP_KERNEL); if (!host) return NULL; @@ -5595,11 +5590,11 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) spin_lock_init(&host->lock); mutex_init(&host->eh_mutex); host->dev = dev; - host->n_ports = max_ports; + host->n_ports = n_ports; kref_init(&host->kref); /* allocate ports bound to this host */ - for (i = 0; i < max_ports; i++) { + for (i = 0; i < n_ports; i++) { struct ata_port *ap; ap = ata_port_alloc(host); @@ -5908,12 +5903,13 @@ int ata_host_register(struct ata_host *host, const struct scsi_host_template *sh return -EINVAL; } - /* Blow away unused ports. This happens when LLD can't - * determine the exact number of ports to allocate at - * allocation time. + /* + * For a driver using ata_host_register(), the ports are allocated by + * ata_host_alloc(), which also allocates the host->ports array. + * The number of array elements must match host->n_ports. */ for (i = host->n_ports; host->ports[i]; i++) - kfree(host->ports[i]); + WARN_ON(host->ports[i]); /* give ports names and add SCSI hosts */ for (i = 0; i < host->n_ports; i++) { diff --git a/include/linux/libata.h b/include/linux/libata.h index 580971e11804..b7c5d3f33368 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1069,7 +1069,7 @@ extern int sata_std_hardreset(struct ata_link *link, unsigned int *class, unsigned long deadline); extern void ata_std_postreset(struct ata_link *link, unsigned int *classes); -extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports); +extern struct ata_host *ata_host_alloc(struct device *dev, int n_ports); extern struct ata_host *ata_host_alloc_pinfo(struct device *dev, const struct ata_port_info * const * ppi, int n_ports); extern void ata_host_get(struct ata_host *host); From patchwork Wed Jun 26 18:00:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713219 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 9483118A93E; Wed, 26 Jun 2024 18:01:41 +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=1719424901; cv=none; b=bYjoUpAqGcTcUNcd74Sk5Of3iVICrwfripge5gtQ98dEPVBxRqljOTB9Qw/krtcl34sawhew4iBLRojG+mxNK8m1AELWi0g/gziD6HCJdDBmwNCQBdqgnI2hRzjDNmx/55hn8HnkD0/0BMtW4VVTxughUiusU0XAB+rzgD/8nIg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424901; c=relaxed/simple; bh=KQ3dNKT37gMd3OcJbj2qIxQav+yEREEO+aRB22o7Cjo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BnGU1jH6993ObICZTAO66eImpsCE3RT851BkGrfL3TKrNpZMKbacP/7QsBWvvSI0jBBf/JKgNFYCbS4J/Fyl+F/3WRmB+Uc2M/yOzVrLC4VjLv5wuP+f0OWC2RAGP/8n47CiDeS6l8ORWEotvg70DLEGgR7NoD/DIwne1rLfh5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cd8foiQS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cd8foiQS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBFD4C116B1; Wed, 26 Jun 2024 18:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424901; bh=KQ3dNKT37gMd3OcJbj2qIxQav+yEREEO+aRB22o7Cjo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cd8foiQSgd2+eWVhKfEyhIMlerEW4zWTs3EG+f6dwgTQ012m6BAXa34VeKZaJ/m4C CZWPsi0YNP451JhqrOvzpUSlWrBnxEjkg20ddVmXrUb8Q8tpyivXRiUwepwq2yPvHc AxrzqRghFlkVcyh6DbQ/UjAlYe1ha+DhqJpkG6VqdR3Vlq2xihmxRolYGzNBhMKvT1 l9fIHmB1jTaqj1W0NY2qNoYwjr4UwKtAqDrIrmI+jwbBJyEN9efeQh+71i/ls2o8Wn nm6ndTSlbpmxbSq91wRQf9tMe9btAtUYqdRFaKBCUV/whNdePZhiM92+xtDtPGjKBU 6djENK+JVfPZw== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , linux-ide@vger.kernel.org Subject: [PATCH v2 08/13] ata: libata-sata: Remove superfluous assignment in ata_sas_port_alloc() Date: Wed, 26 Jun 2024 20:00:38 +0200 Message-ID: <20240626180031.4050226-23-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=776; i=cassel@kernel.org; h=from:subject; bh=KQ3dNKT37gMd3OcJbj2qIxQav+yEREEO+aRB22o7Cjo=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwp0Ktv9y8NKMcW3VfvN4le6htbKNKXINO9O37P09+ QxfvGpXRykLgxgXg6yYIovvD5f9xd3uU44r3rGBmcPKBDKEgYtTACYSGsXIcDV1Z96yTBHnshzp TR88ivJPr4iXr+xqq53utjjzbmA5D8NvlncqxlLhM4qSBCdJzxGy69pakrmOe1WxalS+a8MMkz3 MAA== X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA ata_sas_port_alloc() calls ata_port_alloc() which already assigns ap->lock so there is no need to ata_sas_port_alloc() to assign it again. Reviewed-by: Damien Le Moal Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-sata.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index e7991595bfe5..1a36a5d1d7bc 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1228,7 +1228,6 @@ struct ata_port *ata_sas_port_alloc(struct ata_host *host, return NULL; ap->port_no = 0; - ap->lock = &host->lock; ap->pio_mask = port_info->pio_mask; ap->mwdma_mask = port_info->mwdma_mask; ap->udma_mask = port_info->udma_mask; From patchwork Wed Jun 26 18:00:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713220 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 C90DC158A22; Wed, 26 Jun 2024 18:01:46 +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=1719424906; cv=none; b=b6Et19L3YEcPOZRicKMAkIBMTcvghp6IADgTjfztX2V+DrDrua0q9LOi45ymCcETYUIqiGtNWsSojQxoETwxGuYMRn7d9Mfqdk1k+bDsLF/N0LL8iKKJEysojEQAgW/9tUHzHcQ7YtkWwZJL45ZrQwzYfRA21yir1nOwopx42qY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424906; c=relaxed/simple; bh=ppUpG4EnJX1Q6mJjRxr3G8icwrV8ouUl0tzKUC36+yU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jqQOfRysS6YKmxV6e4L+jKbzKraTPoXIp36R8l8do5G7bV0O/mW/6rW740Ry7NFgYIXl9po6hojHse03W1sakGl1hDbny78a0GpXiQAnAea3dd0IeXX7IpkwdOEEzzu0ZfLiDOom2WnjdBa4DqjpHE2eMs7KLsvEAVMOem+NDg4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tGjGTn80; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tGjGTn80" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FD1BC4AF07; Wed, 26 Jun 2024 18:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424906; bh=ppUpG4EnJX1Q6mJjRxr3G8icwrV8ouUl0tzKUC36+yU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tGjGTn80bPJiXsAe/PE7eU/L0eaFH4AlizVGS1VacQmNmCD+UNX2pXbzk/Ud4pl8w nroUyXnutoAadXdcQVaQuoeShU66Bl3YsdZNKJiAFE9vt1orVaKfqtqBm4efJFdJAc OtmYlS4cKMbYo00fK2CKO9tJolhs59hwx5aAQ1UKEUiJE2LMP6O7OuVBdompgxr6Ob 2YKOsTgnxA5bS7q4+mjgEVm58EoiiPoQ6Z1pzK/bJok9ATZnGxCmZ5g1nTALH41oCB 2ZvQ1jPvgnqRRGTE88i9SDptX7UmOQNNh5FRE+ObCdR4do5GUZ1tElG/Hphxm+lbgA Wepmw0cfFhyDA== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , linux-ide@vger.kernel.org Subject: [PATCH v2 09/13] ata: libata-core: Remove local_port_no struct member Date: Wed, 26 Jun 2024 20:00:39 +0200 Message-ID: <20240626180031.4050226-24-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2611; i=cassel@kernel.org; h=from:subject; bh=ppUpG4EnJX1Q6mJjRxr3G8icwrV8ouUl0tzKUC36+yU=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwp15ikXf+VpsLee0EY6yv/1wo86qCwf8Nz27JegS6 K42MYW/o5SFQYyLQVZMkcX3h8v+4m73KccV79jAzGFlAhnCwMUpABPZ4cfIMMnNcYIa/6oUW/ae 76LpS7l7bu2s8s4+9WzvK+U5AqLFfxkZJn+Z1XQl66/ulCkV20+uU5qr93FxteEMUY/9/ZYPfyy +wwEA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA ap->local_port_no is simply ap->port_no + 1. Since ap->local_port_no can be derived from ap->port_no, there is no need for the ap->local_port_no struct member, so remove ap->local_port_no. Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 5 +---- drivers/ata/libata-transport.c | 3 ++- include/linux/libata.h | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index a213a9c0d0a5..ceee4b6ba3dd 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5464,7 +5464,6 @@ struct ata_port *ata_port_alloc(struct ata_host *host) ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; ap->lock = &host->lock; ap->print_id = -1; - ap->local_port_no = -1; ap->host = host; ap->dev = host->dev; @@ -5912,10 +5911,8 @@ int ata_host_register(struct ata_host *host, const struct scsi_host_template *sh WARN_ON(host->ports[i]); /* give ports names and add SCSI hosts */ - for (i = 0; i < host->n_ports; i++) { + for (i = 0; i < host->n_ports; i++) host->ports[i]->print_id = atomic_inc_return(&ata_print_id); - host->ports[i]->local_port_no = i + 1; - } /* Create associated sysfs transport objects */ for (i = 0; i < host->n_ports; i++) { diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c index d24f201c0ab2..9e24c33388f9 100644 --- a/drivers/ata/libata-transport.c +++ b/drivers/ata/libata-transport.c @@ -217,7 +217,8 @@ static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL) ata_port_simple_attr(nr_pmp_links, nr_pmp_links, "%d\n", int); ata_port_simple_attr(stats.idle_irq, idle_irq, "%ld\n", unsigned long); -ata_port_simple_attr(local_port_no, port_no, "%u\n", unsigned int); +/* We want the port_no sysfs attibute to start at 1 (ap->port_no starts at 0) */ +ata_port_simple_attr(port_no + 1, port_no, "%u\n", unsigned int); static DECLARE_TRANSPORT_CLASS(ata_port_class, "ata_port", NULL, NULL, NULL); diff --git a/include/linux/libata.h b/include/linux/libata.h index b7c5d3f33368..84a7bfbac9fa 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -814,7 +814,6 @@ struct ata_port { /* Flags that change dynamically, protected by ap->lock */ unsigned int pflags; /* ATA_PFLAG_xxx */ unsigned int print_id; /* user visible unique port ID */ - unsigned int local_port_no; /* host local port num */ unsigned int port_no; /* 0 based port no. inside the host */ #ifdef CONFIG_ATA_SFF From patchwork Wed Jun 26 18:00:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713221 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 408BC6E613; Wed, 26 Jun 2024 18:01:52 +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=1719424912; cv=none; b=SXsHja1/fxJJW/RTxN4qiF9f/1lcdsJTrZ1Gc1euyEr6Jo3gHV50UZiRrZgfimmTbTXfTvL4eHujFmn5xWGLnx42XFj5O0FRb97VC2dijdSinhhiA7aq56fhd3Hv2G7ELaQO9l1HHuNcb5SCRiewjm9O50Nko9FR/K5v9laLvaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424912; c=relaxed/simple; bh=+ANSy8S7jRPCn1qaYrZz2sKexsqF72tMosrAwiODGrs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZwziUAm3QpxTtfsEJ/utpatIiZzX3SzaP/iNTIPDHZpwxK42HaweyzgdSK2ny4KUkaTgi8SjXiusRgrOCoLBmVa5QjOrd+P2os96C3RxkExBs5Qnl6gmUbcphNZwE2JowBRLm0QVycSD7GPSQjRSsNj/XsIJ8VIiu6LFSbabL4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VHu4c4Uz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VHu4c4Uz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9582C116B1; Wed, 26 Jun 2024 18:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424912; bh=+ANSy8S7jRPCn1qaYrZz2sKexsqF72tMosrAwiODGrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VHu4c4Uzew2pI0CdAkVvdU/soYcoT0pRd4dTr0GCaQsRI5O+bA6DsV+QtZNwV/U3c xsXyz3C4+SLfWa4s3dR59effKQGShPYA3PT9HgSW1oXJPaoux1mWdH6fR+n2q0HQNh bvNKOa0o45Pszlwlx8VgzzAL0ntFnbo4aXmaBvrNjjvhPOjPVH7EXqC2CWsDQwV/xl WrT6oz2gfCeNibnkKziY9a+bmml/ypp1VY9GCI9GQ1PWhzSKOMZ6nd9NBu3ITzKKtU BiZhcvyy4wIib7F+q03GsGSq5el4O0/AaMQOwT+LrJ55V4efNwuVExpi1PEjxJSxcm 7LybXTOIhF7Yg== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , linux-ide@vger.kernel.org Subject: [PATCH v2 10/13] ata: libata: Assign print_id at port allocation time Date: Wed, 26 Jun 2024 20:00:40 +0200 Message-ID: <20240626180031.4050226-25-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2089; i=cassel@kernel.org; h=from:subject; bh=+ANSy8S7jRPCn1qaYrZz2sKexsqF72tMosrAwiODGrs=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwp2N96Wp/UrK3vQo/8WjjotxIcfMJGZUTPtuF/vy0 ZRTS3jmdZSyMIhxMciKKbL4/nDZX9ztPuW44h0bmDmsTCBDGLg4BWAixc8ZGVZ/4zhe/c1W6E8f 35IpPWWNJ45pp8mf3OTpyiMo0/E7kYnhf+Fk3erUCaXKP0q3X0/5YrEp6sr6P6Glu7UFQp/EhHl O5gEA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA While the assignment of ap->print_id could have been moved to ata_host_alloc(), let's simply move it to ata_port_alloc(). If you allocate a port, you want to give it a unique name that can be used for printing. By moving the ap->print_id assignment to ata_port_alloc(), means that we can also remove the ap->print_id assignment from ata_sas_port_alloc(). This will allow a LLD to use the ata_port_*() print functions before ata_host_register() has been called. Reviewed-by: Damien Le Moal Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 6 +----- drivers/ata/libata-sata.c | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index ceee4b6ba3dd..52c1f0915aef 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5463,7 +5463,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host) ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; ap->lock = &host->lock; - ap->print_id = -1; + ap->print_id = atomic_inc_return(&ata_print_id); ap->host = host; ap->dev = host->dev; @@ -5910,10 +5910,6 @@ int ata_host_register(struct ata_host *host, const struct scsi_host_template *sh for (i = host->n_ports; host->ports[i]; i++) WARN_ON(host->ports[i]); - /* give ports names and add SCSI hosts */ - for (i = 0; i < host->n_ports; i++) - host->ports[i]->print_id = atomic_inc_return(&ata_print_id); - /* Create associated sysfs transport objects */ for (i = 0; i < host->n_ports; i++) { rc = ata_tport_add(host->dev,host->ports[i]); diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 1a36a5d1d7bc..b602247604dc 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1234,7 +1234,6 @@ struct ata_port *ata_sas_port_alloc(struct ata_host *host, ap->flags |= port_info->flags; ap->ops = port_info->port_ops; ap->cbl = ATA_CBL_SATA; - ap->print_id = atomic_inc_return(&ata_print_id); return ap; } From patchwork Wed Jun 26 18:00:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713222 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 F1C116E613; Wed, 26 Jun 2024 18:01:57 +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=1719424918; cv=none; b=FQdZirkLlbE7d5VS5epRB5dYncaSb8kxuDWE0XWDVwOa4Bg5bjACqvcqJecPMfb6U0y7M/1huxiN7maSzFcNvWTBfp8GAMWvZ243/HA1Pk37qgXmcFQy5q2vyO/xp3tCHlGQJ+GDZFS+IciVryYs4b//WXymsIpeNEyW3tBbDKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424918; c=relaxed/simple; bh=k1HCGiw/R6mXVVFM15Im522WtWq7BVtq4BOm1kkTSZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nGsM9KpjVUlhQPhTblu4ZAaObLMAqA7tCCe/W65abm8m2gPErPawzHBfpOPhOC75hMmaG86+VERAl5mxcbT4Ht/sv4sbrs7LvIR/L9Rmg1ZHBrO87oxxHDnXH3W9CSvGlpYl7+uBP9mcW7+rZYZaApXxJRHN3hBv0I9y87QqVRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RImxqgAe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RImxqgAe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EB1FC116B1; Wed, 26 Jun 2024 18:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424917; bh=k1HCGiw/R6mXVVFM15Im522WtWq7BVtq4BOm1kkTSZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RImxqgAeGHtd7mv5WYPVKRRT8T5wrMrcOgLCtW40o2gJx1odJiVVVX9zoWepHA3uP lsOM1PwAx7Rb5G98udfe1snfQcLej954kTTs+JBF8Z0XY6s8eNHig2QK+jY60uatMc oAMlEdz9k9tZq6nf/oueWG9HnoOGmBzuRO/EU0AWlg1FSglcLD+OMJgcyJkUkSnFyC kLRVUUDk5cIPfMkpJ03ZnaY1mhXgkRZZAHGIguwdFTLcfg8v7MNJJzDMq8rNawrEXD 0YjqLP6lHbLED4HcdWqYLxbd658UrpEdERzXpFLJ81yzZro2++GDVLHYOs+Hbf/K73 G1bXQE+TQB/dA== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , linux-ide@vger.kernel.org Subject: [PATCH v2 11/13] ata: libata-core: Reuse available ata_port print_ids Date: Wed, 26 Jun 2024 20:00:41 +0200 Message-ID: <20240626180031.4050226-26-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1709; i=cassel@kernel.org; h=from:subject; bh=k1HCGiw/R6mXVVFM15Im522WtWq7BVtq4BOm1kkTSZ4=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwp33qR/NcHma7Gj/9+8vM9U31xPEl1qW6YX96/7ls zg26LRBRykLgxgXg6yYIovvD5f9xd3uU44r3rGBmcPKBDKEgYtTACZycBrDX7kbMkky7nFBIae5 E16t3v+HKX3+/EkrRVYfenvm4rmJG3MY/sc96Nk5Z5/FZc+7J+PbV87oXrbjy+2Xk7+3KIpMeT9 vyyYGAA== X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA Currently, the ata_port print_ids are increased indefinitely, even when there are lower ids available. E.g. on first boot you will have ata1-ata6 assigned. After a rmmod + modprobe, you will instead have ata7-ata12 assigned. Move to use the ida_alloc() API, such that print_ids will get reused. This means that even after a rmmod + modprobe, the ports will be assigned print_ids ata1-ata6. Signed-off-by: Niklas Cassel Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 52c1f0915aef..846ab99e0cd3 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -86,7 +86,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev); static void ata_dev_xfermask(struct ata_device *dev); static unsigned long ata_dev_blacklisted(const struct ata_device *dev); -atomic_t ata_print_id = ATOMIC_INIT(0); +static DEFINE_IDA(ata_ida); #ifdef CONFIG_ATA_FORCE struct ata_force_param { @@ -5463,7 +5463,11 @@ struct ata_port *ata_port_alloc(struct ata_host *host) ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; ap->lock = &host->lock; - ap->print_id = atomic_inc_return(&ata_print_id); + ap->print_id = ida_alloc_min(&ata_ida, 1, GFP_KERNEL); + if (ap->print_id < 0) { + kfree(ap); + return NULL; + } ap->host = host; ap->dev = host->dev; @@ -5497,6 +5501,7 @@ void ata_port_free(struct ata_port *ap) kfree(ap->pmp_link); kfree(ap->slave_link); kfree(ap->ncq_sense_buf); + ida_free(&ata_ida, ap->print_id); kfree(ap); } EXPORT_SYMBOL_GPL(ata_port_free); From patchwork Wed Jun 26 18:00:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713224 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 5468018F2E3; Wed, 26 Jun 2024 18:02:03 +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=1719424923; cv=none; b=cdL+IvTdVF48n50AfLPisNg3e/HpE/l6gyg5URpJEWh04z7SwooLMQ6ctyGX519OpRZGM9aUPocrAWJvcbsbbzhbsIWHBALGTXPmLI5v336I/2x0unRBVo4HuXeNCTj+ESCKYkqE9ZjZLdMa3VsJMFAtKfSZ3fygu+P7lk4YPvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424923; c=relaxed/simple; bh=DBAoA6YQndyFztrdyhctAMXii6o3QZHeeA6CbFnpSag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OUQ8ZYQVob3F+9s2OKl1R9eiL/ch5kL6/4YvAGZJzVrnYCo5SQTPmtxPM0uG65sxv6IPQY1alGGUKs3Vv5v3jcqAZioKdzJnb1Hxs3poEm1Amaai0kX3dZCtWKzlxlLztLwxrFEM+e3xDQfVeVhmAFgMpMympOq4CUT5dyQ7oUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kQgUeZEU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kQgUeZEU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04BCCC32782; Wed, 26 Jun 2024 18:01:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424923; bh=DBAoA6YQndyFztrdyhctAMXii6o3QZHeeA6CbFnpSag=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kQgUeZEU/icnoqiqHWApJKo1Vos1k+DQZi9uooi6VxwSiDDwtlBGYP4ij5nms6ufY Z6IYfQKMtD2YG+NhsrUPvoXOUW9Vn2N7CIXr8+i+6PltAWby/nbgx/9/mlkr120IRd qjI6nnqkSyKVmFkP6jrGuWB1rWvHIOHWMLDpRgriI/tWi2EJ7lk6PNgl9VgMlNvYw/ mTfsQ0epEeIYOOYe23qT2heZ6L9v+PutJt37T5o8/o77RpAdwu4yA3SM5oU3NbZFaX QQ1S3/2COidIivc2NTG2iGkK04mOdm/5t1+I6yyBrWtIoFb74YfzOscpU8tIkVLkg4 QDAvpwGQ/cD/Q== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel , John Garry , Jason Yan , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org Subject: [PATCH v2 12/13] ata,scsi: Remove useless ata_sas_port_alloc() wrapper Date: Wed, 26 Jun 2024 20:00:42 +0200 Message-ID: <20240626180031.4050226-27-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4589; i=cassel@kernel.org; h=from:subject; bh=DBAoA6YQndyFztrdyhctAMXii6o3QZHeeA6CbFnpSag=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwl3mCFr9vVqdsOr1OimnTz944g7kt+b8STy/0szF1 OTbzOd/OkpZGMS4GGTFFFl8f7jsL+52n3Jc8Y4NzBxWJpAhDFycAjCR1QaMDEf+zwzW9P9lE2a5 9evrj29KMz9lvWfTmBX3aanRLiHxXamMDO/NGju/u88rCL12f9a2m1+qLL++eb6pv75jqnfE2uy I/TwA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA Now when the ap->print_id assignment has moved to ata_port_alloc(), we can remove the useless ata_sas_port_alloc() wrapper. Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 1 + drivers/ata/libata-sata.c | 35 ----------------------------------- drivers/ata/libata.h | 1 - drivers/scsi/libsas/sas_ata.c | 10 ++++++++-- include/linux/libata.h | 3 +-- 5 files changed, 10 insertions(+), 40 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 846ab99e0cd3..11ecfdea5959 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5492,6 +5492,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host) return ap; } +EXPORT_SYMBOL_GPL(ata_port_alloc); void ata_port_free(struct ata_port *ap) { diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index b602247604dc..48660d445602 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -1204,41 +1204,6 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth) } EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth); -/** - * ata_sas_port_alloc - Allocate port for a SAS attached SATA device - * @host: ATA host container for all SAS ports - * @port_info: Information from low-level host driver - * @shost: SCSI host that the scsi device is attached to - * - * LOCKING: - * PCI/etc. bus probe sem. - * - * RETURNS: - * ata_port pointer on success / NULL on failure. - */ - -struct ata_port *ata_sas_port_alloc(struct ata_host *host, - struct ata_port_info *port_info, - struct Scsi_Host *shost) -{ - struct ata_port *ap; - - ap = ata_port_alloc(host); - if (!ap) - return NULL; - - ap->port_no = 0; - ap->pio_mask = port_info->pio_mask; - ap->mwdma_mask = port_info->mwdma_mask; - ap->udma_mask = port_info->udma_mask; - ap->flags |= port_info->flags; - ap->ops = port_info->port_ops; - ap->cbl = ATA_CBL_SATA; - - return ap; -} -EXPORT_SYMBOL_GPL(ata_sas_port_alloc); - /** * ata_sas_device_configure - Default device_configure routine for libata * devices diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 38ce13b55474..e930ac948eac 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -82,7 +82,6 @@ extern void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp); extern int sata_link_init_spd(struct ata_link *link); extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); -extern struct ata_port *ata_port_alloc(struct ata_host *host); extern const char *sata_spd_string(unsigned int spd); extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log, u8 page, void *buf, unsigned int sectors); diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c index e8987dce585f..eecdd1525a18 100644 --- a/drivers/scsi/libsas/sas_ata.c +++ b/drivers/scsi/libsas/sas_ata.c @@ -597,13 +597,19 @@ int sas_ata_init(struct domain_device *found_dev) ata_host_init(ata_host, ha->dev, &sas_sata_ops); - ap = ata_sas_port_alloc(ata_host, &sata_port_info, shost); + ap = ata_port_alloc(ata_host); if (!ap) { - pr_err("ata_sas_port_alloc failed.\n"); + pr_err("ata_port_alloc failed.\n"); rc = -ENODEV; goto free_host; } + ap->port_no = 0; + ap->pio_mask = sata_port_info.pio_mask; + ap->mwdma_mask = sata_port_info.mwdma_mask; + ap->udma_mask = sata_port_info.udma_mask; + ap->flags |= sata_port_info.flags; + ap->ops = sata_port_info.port_ops; ap->private_data = found_dev; ap->cbl = ATA_CBL_SATA; ap->scsi_host = shost; diff --git a/include/linux/libata.h b/include/linux/libata.h index 84a7bfbac9fa..17394098bee9 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -1244,9 +1244,8 @@ extern int sata_link_debounce(struct ata_link *link, extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy, bool spm_wakeup); extern int ata_slave_link_init(struct ata_port *ap); -extern struct ata_port *ata_sas_port_alloc(struct ata_host *, - struct ata_port_info *, struct Scsi_Host *); extern void ata_port_probe(struct ata_port *ap); +extern struct ata_port *ata_port_alloc(struct ata_host *host); extern void ata_port_free(struct ata_port *ap); extern int ata_tport_add(struct device *parent, struct ata_port *ap); extern void ata_tport_delete(struct ata_port *ap); From patchwork Wed Jun 26 18:00:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 13713225 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 EE32B18A93E; Wed, 26 Jun 2024 18:02:08 +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=1719424929; cv=none; b=Hw9tcDeVd7ssHLt1L3oBdQCn+Hs6/NPERoSTiVhb9yVMaEkY9t1zGGvjXaCRfyRo3H0hk8TaoXecsd1ksUFKClxr4aGjsWoaViORwxrUo1C1v34ypXI0pYk2eiAsd/8UgtHWiBrpS/nqqlkZ8lyteZzLoU2o/oM+BIh+dTP4cmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719424929; c=relaxed/simple; bh=UAY0ldpH6pilPESHp2oE7IoyK/F1c5egr25Iq7TAGmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sPMfXB4ZvEN0Ib3ZzWaXk89X4vMwGFKYl44koU1fAsKmmGWAJznzbkoAwn3HMBgQqGsuWzb++K3a9HRDrhlFv4CfUMt4DTplg25NwSj/xqw+VTXmieyAQIk5qAQUta14i+OAyAtDB6GPPvvfEkU+XarbMO7lkfy0OmRRLQxInDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CAUuHnyb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CAUuHnyb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D3B6C32782; Wed, 26 Jun 2024 18:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719424928; bh=UAY0ldpH6pilPESHp2oE7IoyK/F1c5egr25Iq7TAGmE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CAUuHnyb3lHfF2pinK95cNgCDa+TSZD/v9fDNzi1boJ6GR6h4G4tKIFUXi00fo0oY apIDyjLV86iCVvU8Gq7COf7R0Qqx3FzioIza2CbllnD7DZAVqBYD25gmcKPwHunnQi jX5VO/VLTdvSi7TqOX54LfdcZ8jT9yXatpKl89dROmQloISgZmpL6CSYDSvKGwo896 7uZ65eAVplObuuwIr7719/Cdb0iG/xRVkTyXBFOq0FGUOstsgSs5Bqeh9kSv1KD/M0 xJGQ5T/jYOCiNsVp54RBJmLX3we38yDqGEtbQJiTT+tYI3uuQHYKqOn71jTJOfgXSf eOH0HJewIo2zQ== From: Niklas Cassel To: Damien Le Moal , Niklas Cassel Cc: linux-scsi@vger.kernel.org, John Garry , Jason Yan , "Martin K. Petersen" , "James E.J. Bottomley" , linux-ide@vger.kernel.org Subject: [PATCH v2 13/13] ata: ahci: Add debug print for external port Date: Wed, 26 Jun 2024 20:00:43 +0200 Message-ID: <20240626180031.4050226-28-cassel@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240626180031.4050226-15-cassel@kernel.org> References: <20240626180031.4050226-15-cassel@kernel.org> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=950; i=cassel@kernel.org; h=from:subject; bh=UAY0ldpH6pilPESHp2oE7IoyK/F1c5egr25Iq7TAGmE=; b=owGbwMvMwCV2MsVw8cxjvkWMp9WSGNJqwl0OKmSze751+e/3x2OW45fo++U8PUn/r+2cLM76c jObWVRIRykLgxgXg6yYIovvD5f9xd3uU44r3rGBmcPKBDKEgYtTACayoIqRYeLnFv2rLQZfwyyE c33m9u+/tnWJZGeC2eGU1ec3Xr3hL87wzyR/kwqzdOmqf10Jux9uXF9X/OrB3oJ3t+adzXhccCJ 9GRsA X-Developer-Key: i=cassel@kernel.org; a=openpgp; fpr=5ADE635C0E631CBBD5BE065A352FE6582ED9B5DA Add a debug print that tells us if LPM is not getting enabled because the port is external. Reviewed-by: Damien Le Moal Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/ahci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index fc6fd583faf8..a05c17249448 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c @@ -1732,8 +1732,10 @@ static void ahci_update_initial_lpm_policy(struct ata_port *ap) * Management Interaction in AHCI 1.3.1. Therefore, do not enable * LPM if the port advertises itself as an external port. */ - if (ap->pflags & ATA_PFLAG_EXTERNAL) + if (ap->pflags & ATA_PFLAG_EXTERNAL) { + ata_port_dbg(ap, "external port, not enabling LPM\n"); return; + } /* If no LPM states are supported by the HBA, do not bother with LPM */ if ((ap->host->flags & ATA_HOST_NO_PART) &&