Skip to content

Commit 018d5ef

Browse files
mitahtejun
authored andcommitted
ata: ahci_platform: fix owner module reference mismatch for scsi host
The owner module reference of the ahci platform's scsi_host is initialized to libahci_platform's one, because these drivers use a scsi_host_template defined in libahci_platform. So these drivers can be unloaded even if the scsi device is being accessed. This fixes it by pushing the scsi_host_template from libahci_platform to all leaf drivers. The scsi_host_template is passed through a new argument of ahci_platform_init_host(). Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: "James E.J. Bottomley" <JBottomley@parallels.com> Cc: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org
1 parent cedda4c commit 018d5ef

12 files changed

Lines changed: 89 additions & 23 deletions

File tree

‎drivers/ata/ahci.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ extern int ahci_ignore_sss;
354354
extern struct device_attribute *ahci_shost_attrs[];
355355
extern struct device_attribute *ahci_sdev_attrs[];
356356

357+
/*
358+
* This must be instantiated by the edge drivers. Read the comments
359+
* for ATA_BASE_SHT
360+
*/
357361
#define AHCI_SHT(drv_name) \
358362
ATA_NCQ_SHT(drv_name), \
359363
.can_queue = AHCI_MAX_CMDS - 1, \

‎drivers/ata/ahci_da850.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <linux/ahci_platform.h>
1717
#include "ahci.h"
1818

19+
#define DRV_NAME "ahci_da850"
20+
1921
/* SATA PHY Control Register offset from AHCI base */
2022
#define SATA_P0PHYCR_REG 0x178
2123

@@ -59,6 +61,10 @@ static const struct ata_port_info ahci_da850_port_info = {
5961
.port_ops = &ahci_platform_ops,
6062
};
6163

64+
static struct scsi_host_template ahci_platform_sht = {
65+
AHCI_SHT(DRV_NAME),
66+
};
67+
6268
static int ahci_da850_probe(struct platform_device *pdev)
6369
{
6470
struct device *dev = &pdev->dev;
@@ -85,7 +91,8 @@ static int ahci_da850_probe(struct platform_device *pdev)
8591

8692
da850_sata_init(dev, pwrdn_reg, hpriv->mmio);
8793

88-
rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info);
94+
rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info,
95+
&ahci_platform_sht);
8996
if (rc)
9097
goto disable_resources;
9198

@@ -102,7 +109,7 @@ static struct platform_driver ahci_da850_driver = {
102109
.probe = ahci_da850_probe,
103110
.remove = ata_platform_remove_one,
104111
.driver = {
105-
.name = "ahci_da850",
112+
.name = DRV_NAME,
106113
.pm = &ahci_da850_pm_ops,
107114
},
108115
};

‎drivers/ata/ahci_imx.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <linux/libata.h>
2929
#include "ahci.h"
3030

31+
#define DRV_NAME "ahci-imx"
32+
3133
enum {
3234
/* Timer 1-ms Register */
3335
IMX_TIMER1MS = 0x00e0,
@@ -520,6 +522,10 @@ static u32 imx_ahci_parse_props(struct device *dev,
520522
return reg_value;
521523
}
522524

525+
static struct scsi_host_template ahci_platform_sht = {
526+
AHCI_SHT(DRV_NAME),
527+
};
528+
523529
static int imx_ahci_probe(struct platform_device *pdev)
524530
{
525531
struct device *dev = &pdev->dev;
@@ -616,7 +622,8 @@ static int imx_ahci_probe(struct platform_device *pdev)
616622
reg_val = clk_get_rate(imxpriv->ahb_clk) / 1000;
617623
writel(reg_val, hpriv->mmio + IMX_TIMER1MS);
618624

619-
ret = ahci_platform_init_host(pdev, hpriv, &ahci_imx_port_info);
625+
ret = ahci_platform_init_host(pdev, hpriv, &ahci_imx_port_info,
626+
&ahci_platform_sht);
620627
if (ret)
621628
goto disable_sata;
622629

@@ -674,7 +681,7 @@ static struct platform_driver imx_ahci_driver = {
674681
.probe = imx_ahci_probe,
675682
.remove = ata_platform_remove_one,
676683
.driver = {
677-
.name = "ahci-imx",
684+
.name = DRV_NAME,
678685
.of_match_table = imx_ahci_of_match,
679686
.pm = &ahci_imx_pm_ops,
680687
},

‎drivers/ata/ahci_mvebu.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <linux/platform_device.h>
2020
#include "ahci.h"
2121

22+
#define DRV_NAME "ahci-mvebu"
23+
2224
#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
2325
#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
2426

@@ -67,6 +69,10 @@ static const struct ata_port_info ahci_mvebu_port_info = {
6769
.port_ops = &ahci_platform_ops,
6870
};
6971

72+
static struct scsi_host_template ahci_platform_sht = {
73+
AHCI_SHT(DRV_NAME),
74+
};
75+
7076
static int ahci_mvebu_probe(struct platform_device *pdev)
7177
{
7278
struct ahci_host_priv *hpriv;
@@ -88,7 +94,8 @@ static int ahci_mvebu_probe(struct platform_device *pdev)
8894
ahci_mvebu_mbus_config(hpriv, dram);
8995
ahci_mvebu_regret_option(hpriv);
9096

91-
rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info);
97+
rc = ahci_platform_init_host(pdev, hpriv, &ahci_mvebu_port_info,
98+
&ahci_platform_sht);
9299
if (rc)
93100
goto disable_resources;
94101

@@ -114,7 +121,7 @@ static struct platform_driver ahci_mvebu_driver = {
114121
.probe = ahci_mvebu_probe,
115122
.remove = ata_platform_remove_one,
116123
.driver = {
117-
.name = "ahci-mvebu",
124+
.name = DRV_NAME,
118125
.of_match_table = ahci_mvebu_of_match,
119126
},
120127
};

‎drivers/ata/ahci_platform.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@
2222
#include <linux/ahci_platform.h>
2323
#include "ahci.h"
2424

25+
#define DRV_NAME "ahci"
26+
2527
static const struct ata_port_info ahci_port_info = {
2628
.flags = AHCI_FLAG_COMMON,
2729
.pio_mask = ATA_PIO4,
2830
.udma_mask = ATA_UDMA6,
2931
.port_ops = &ahci_platform_ops,
3032
};
3133

34+
static struct scsi_host_template ahci_platform_sht = {
35+
AHCI_SHT(DRV_NAME),
36+
};
37+
3238
static int ahci_probe(struct platform_device *pdev)
3339
{
3440
struct device *dev = &pdev->dev;
@@ -46,7 +52,8 @@ static int ahci_probe(struct platform_device *pdev)
4652
if (of_device_is_compatible(dev->of_node, "hisilicon,hisi-ahci"))
4753
hpriv->flags |= AHCI_HFLAG_NO_FBS | AHCI_HFLAG_NO_NCQ;
4854

49-
rc = ahci_platform_init_host(pdev, hpriv, &ahci_port_info);
55+
rc = ahci_platform_init_host(pdev, hpriv, &ahci_port_info,
56+
&ahci_platform_sht);
5057
if (rc)
5158
goto disable_resources;
5259

@@ -75,7 +82,7 @@ static struct platform_driver ahci_driver = {
7582
.probe = ahci_probe,
7683
.remove = ata_platform_remove_one,
7784
.driver = {
78-
.name = "ahci",
85+
.name = DRV_NAME,
7986
.of_match_table = ahci_of_match,
8087
.pm = &ahci_pm_ops,
8188
},

‎drivers/ata/ahci_st.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include "ahci.h"
2525

26+
#define DRV_NAME "st_ahci"
27+
2628
#define ST_AHCI_OOBR 0xbc
2729
#define ST_AHCI_OOBR_WE BIT(31)
2830
#define ST_AHCI_OOBR_CWMIN_SHIFT 24
@@ -140,6 +142,10 @@ static const struct ata_port_info st_ahci_port_info = {
140142
.port_ops = &st_ahci_port_ops,
141143
};
142144

145+
static struct scsi_host_template ahci_platform_sht = {
146+
AHCI_SHT(DRV_NAME),
147+
};
148+
143149
static int st_ahci_probe(struct platform_device *pdev)
144150
{
145151
struct st_ahci_drv_data *drv_data;
@@ -166,7 +172,8 @@ static int st_ahci_probe(struct platform_device *pdev)
166172
if (err)
167173
return err;
168174

169-
err = ahci_platform_init_host(pdev, hpriv, &st_ahci_port_info);
175+
err = ahci_platform_init_host(pdev, hpriv, &st_ahci_port_info,
176+
&ahci_platform_sht);
170177
if (err) {
171178
ahci_platform_disable_resources(hpriv);
172179
return err;
@@ -229,7 +236,7 @@ MODULE_DEVICE_TABLE(of, st_ahci_match);
229236

230237
static struct platform_driver st_ahci_driver = {
231238
.driver = {
232-
.name = "st_ahci",
239+
.name = DRV_NAME,
233240
.pm = &st_ahci_pm_ops,
234241
.of_match_table = of_match_ptr(st_ahci_match),
235242
},

‎drivers/ata/ahci_sunxi.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <linux/regulator/consumer.h>
2828
#include "ahci.h"
2929

30+
#define DRV_NAME "ahci-sunxi"
31+
3032
/* Insmod parameters */
3133
static bool enable_pmp;
3234
module_param(enable_pmp, bool, 0);
@@ -169,6 +171,10 @@ static const struct ata_port_info ahci_sunxi_port_info = {
169171
.port_ops = &ahci_platform_ops,
170172
};
171173

174+
static struct scsi_host_template ahci_platform_sht = {
175+
AHCI_SHT(DRV_NAME),
176+
};
177+
172178
static int ahci_sunxi_probe(struct platform_device *pdev)
173179
{
174180
struct device *dev = &pdev->dev;
@@ -200,7 +206,8 @@ static int ahci_sunxi_probe(struct platform_device *pdev)
200206
if (!enable_pmp)
201207
hpriv->flags |= AHCI_HFLAG_NO_PMP;
202208

203-
rc = ahci_platform_init_host(pdev, hpriv, &ahci_sunxi_port_info);
209+
rc = ahci_platform_init_host(pdev, hpriv, &ahci_sunxi_port_info,
210+
&ahci_platform_sht);
204211
if (rc)
205212
goto disable_resources;
206213

@@ -251,7 +258,7 @@ static struct platform_driver ahci_sunxi_driver = {
251258
.probe = ahci_sunxi_probe,
252259
.remove = ata_platform_remove_one,
253260
.driver = {
254-
.name = "ahci-sunxi",
261+
.name = DRV_NAME,
255262
.of_match_table = ahci_sunxi_of_match,
256263
.pm = &ahci_sunxi_pm_ops,
257264
},

‎drivers/ata/ahci_tegra.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
#include "ahci.h"
3333

34+
#define DRV_NAME "tegra-ahci"
35+
3436
#define SATA_CONFIGURATION_0 0x180
3537
#define SATA_CONFIGURATION_EN_FPCI BIT(0)
3638

@@ -289,6 +291,10 @@ static const struct of_device_id tegra_ahci_of_match[] = {
289291
};
290292
MODULE_DEVICE_TABLE(of, tegra_ahci_of_match);
291293

294+
static struct scsi_host_template ahci_platform_sht = {
295+
AHCI_SHT(DRV_NAME),
296+
};
297+
292298
static int tegra_ahci_probe(struct platform_device *pdev)
293299
{
294300
struct ahci_host_priv *hpriv;
@@ -354,7 +360,8 @@ static int tegra_ahci_probe(struct platform_device *pdev)
354360
if (ret)
355361
return ret;
356362

357-
ret = ahci_platform_init_host(pdev, hpriv, &ahci_tegra_port_info);
363+
ret = ahci_platform_init_host(pdev, hpriv, &ahci_tegra_port_info,
364+
&ahci_platform_sht);
358365
if (ret)
359366
goto deinit_controller;
360367

@@ -370,7 +377,7 @@ static struct platform_driver tegra_ahci_driver = {
370377
.probe = tegra_ahci_probe,
371378
.remove = ata_platform_remove_one,
372379
.driver = {
373-
.name = "tegra-ahci",
380+
.name = DRV_NAME,
374381
.of_match_table = tegra_ahci_of_match,
375382
},
376383
/* LP0 suspend support not implemented */

‎drivers/ata/ahci_xgene.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <linux/phy/phy.h>
3131
#include "ahci.h"
3232

33+
#define DRV_NAME "xgene-ahci"
34+
3335
/* Max # of disk per a controller */
3436
#define MAX_AHCI_CHN_PERCTR 2
3537

@@ -621,6 +623,10 @@ static int xgene_ahci_mux_select(struct xgene_ahci_context *ctx)
621623
return val & CFG_SATA_ENET_SELECT_MASK ? -1 : 0;
622624
}
623625

626+
static struct scsi_host_template ahci_platform_sht = {
627+
AHCI_SHT(DRV_NAME),
628+
};
629+
624630
static int xgene_ahci_probe(struct platform_device *pdev)
625631
{
626632
struct device *dev = &pdev->dev;
@@ -698,7 +704,8 @@ static int xgene_ahci_probe(struct platform_device *pdev)
698704
skip_clk_phy:
699705
hpriv->flags = AHCI_HFLAG_NO_PMP | AHCI_HFLAG_NO_NCQ;
700706

701-
rc = ahci_platform_init_host(pdev, hpriv, &xgene_ahci_port_info);
707+
rc = ahci_platform_init_host(pdev, hpriv, &xgene_ahci_port_info,
708+
&ahci_platform_sht);
702709
if (rc)
703710
goto disable_resources;
704711

@@ -720,7 +727,7 @@ static struct platform_driver xgene_ahci_driver = {
720727
.probe = xgene_ahci_probe,
721728
.remove = ata_platform_remove_one,
722729
.driver = {
723-
.name = "xgene-ahci",
730+
.name = DRV_NAME,
724731
.of_match_table = xgene_ahci_of_match,
725732
},
726733
};

‎drivers/ata/libahci_platform.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ struct ata_port_operations ahci_platform_ops = {
3535
};
3636
EXPORT_SYMBOL_GPL(ahci_platform_ops);
3737

38-
static struct scsi_host_template ahci_platform_sht = {
39-
AHCI_SHT("ahci_platform"),
40-
};
41-
4238
/**
4339
* ahci_platform_enable_phys - Enable PHYs
4440
* @hpriv: host private area to store config values
@@ -494,6 +490,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
494490
* @pdev: platform device pointer for the host
495491
* @hpriv: ahci-host private data for the host
496492
* @pi_template: template for the ata_port_info to use
493+
* @sht: scsi_host_template to use when registering
497494
*
498495
* This function does all the usual steps needed to bring up an
499496
* ahci-platform host, note any necessary resources (ie clks, phys, etc.)
@@ -504,7 +501,8 @@ EXPORT_SYMBOL_GPL(ahci_platform_get_resources);
504501
*/
505502
int ahci_platform_init_host(struct platform_device *pdev,
506503
struct ahci_host_priv *hpriv,
507-
const struct ata_port_info *pi_template)
504+
const struct ata_port_info *pi_template,
505+
struct scsi_host_template *sht)
508506
{
509507
struct device *dev = &pdev->dev;
510508
struct ata_port_info pi = *pi_template;
@@ -588,7 +586,7 @@ int ahci_platform_init_host(struct platform_device *pdev,
588586
ahci_init_controller(host);
589587
ahci_print_info(host, "platform");
590588

591-
return ahci_host_activate(host, irq, &ahci_platform_sht);
589+
return ahci_host_activate(host, irq, sht);
592590
}
593591
EXPORT_SYMBOL_GPL(ahci_platform_init_host);
594592

0 commit comments

Comments
 (0)