Skip to content

Commit 82f0832

Browse files
committed
cxl/hdm: Fix double allocation of @cxlhdm
devm_cxl_setup_emulated_hdm() reallocates an instance of @cxlhdm that was already allocated at the start of devm_cxl_setup_hdm(). Only one is needed and devm_cxl_setup_emulated_hdm() does not do enough to warrant being an explicit helper. Fixes: 4474ce5 ("cxl/hdm: Create emulated cxl_hdm for devices that do not have HDM decoders") Tested-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/167703067936.185722.7908921750127154779.stgit@dwillia2-xfh.jf.intel.com Link: https://lore.kernel.org/r/168012574357.221280.5001364964799725366.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent eeac8ed commit 82f0832

File tree

1 file changed

+6
-28
lines changed

1 file changed

+6
-28
lines changed

drivers/cxl/core/hdm.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,6 @@ static int map_hdm_decoder_regs(struct cxl_port *port, void __iomem *crb,
101101
BIT(CXL_CM_CAP_CAP_ID_HDM));
102102
}
103103

104-
static struct cxl_hdm *devm_cxl_setup_emulated_hdm(struct cxl_port *port,
105-
struct cxl_endpoint_dvsec_info *info)
106-
{
107-
struct device *dev = &port->dev;
108-
struct cxl_hdm *cxlhdm;
109-
110-
if (!info->mem_enabled)
111-
return ERR_PTR(-ENODEV);
112-
113-
cxlhdm = devm_kzalloc(dev, sizeof(*cxlhdm), GFP_KERNEL);
114-
if (!cxlhdm)
115-
return ERR_PTR(-ENOMEM);
116-
117-
cxlhdm->port = port;
118-
cxlhdm->decoder_count = info->ranges;
119-
cxlhdm->target_count = info->ranges;
120-
dev_set_drvdata(&port->dev, cxlhdm);
121-
122-
return cxlhdm;
123-
}
124-
125104
/**
126105
* devm_cxl_setup_hdm - map HDM decoder component registers
127106
* @port: cxl_port to map
@@ -138,13 +117,14 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port,
138117
cxlhdm = devm_kzalloc(dev, sizeof(*cxlhdm), GFP_KERNEL);
139118
if (!cxlhdm)
140119
return ERR_PTR(-ENOMEM);
141-
142120
cxlhdm->port = port;
143-
crb = ioremap(port->component_reg_phys, CXL_COMPONENT_REG_BLOCK_SIZE);
144-
if (!crb) {
145-
if (info && info->mem_enabled)
146-
return devm_cxl_setup_emulated_hdm(port, info);
121+
dev_set_drvdata(dev, cxlhdm);
147122

123+
crb = ioremap(port->component_reg_phys, CXL_COMPONENT_REG_BLOCK_SIZE);
124+
if (!crb && info && info->mem_enabled) {
125+
cxlhdm->decoder_count = info->ranges;
126+
return cxlhdm;
127+
} else if (!crb) {
148128
dev_err(dev, "No component registers mapped\n");
149129
return ERR_PTR(-ENXIO);
150130
}
@@ -160,8 +140,6 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port,
160140
return ERR_PTR(-ENXIO);
161141
}
162142

163-
dev_set_drvdata(dev, cxlhdm);
164-
165143
return cxlhdm;
166144
}
167145
EXPORT_SYMBOL_NS_GPL(devm_cxl_setup_hdm, CXL);

0 commit comments

Comments
 (0)