Skip to content

Commit 69c9961

Browse files
committed
cxl/region: Fix region commit uninitialized variable warning
0day robot reports: drivers/cxl/core/region.c:196 cxl_region_decode_commit() error: uninitialized symbol 'rc'. The re-checking of loop termination conditions to determine "success" makes it hard to see that @rc is initialized in all cases. Remove those to make it explicit that @rc reflects a commit error and that the rest of logic is concerned with unwinding committed decoders. This change potentially results in cxl_region_decode_reset() being called with @count == 0 where it was not called before, but cxl_region_decode_reset() treats that as a nop. Fixes: 176baef ("cxl/hdm: Commit decoder state to hardware") Reported-by: kernel test robot <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: http://lore.kernel.org/r/165951148105.967013.14191992449932268431.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 8d42854 commit 69c9961

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

drivers/cxl/core/region.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static int cxl_region_decode_reset(struct cxl_region *cxlr, int count)
159159
static int cxl_region_decode_commit(struct cxl_region *cxlr)
160160
{
161161
struct cxl_region_params *p = &cxlr->params;
162-
int i, rc;
162+
int i, rc = 0;
163163

164164
for (i = 0; i < p->nr_targets; i++) {
165165
struct cxl_endpoint_decoder *cxled = p->targets[i];
@@ -179,27 +179,23 @@ static int cxl_region_decode_commit(struct cxl_region *cxlr)
179179
break;
180180
}
181181

182-
/* success, all decoders up to the root are programmed */
183-
if (is_cxl_root(iter))
184-
continue;
182+
if (rc) {
183+
/* programming @iter failed, teardown */
184+
for (ep = cxl_ep_load(iter, cxlmd); ep && iter;
185+
iter = ep->next, ep = cxl_ep_load(iter, cxlmd)) {
186+
cxl_rr = cxl_rr_load(iter, cxlr);
187+
cxld = cxl_rr->decoder;
188+
cxld->reset(cxld);
189+
}
185190

186-
/* programming @iter failed, teardown */
187-
for (ep = cxl_ep_load(iter, cxlmd); ep && iter;
188-
iter = ep->next, ep = cxl_ep_load(iter, cxlmd)) {
189-
cxl_rr = cxl_rr_load(iter, cxlr);
190-
cxld = cxl_rr->decoder;
191-
cxld->reset(cxld);
191+
cxled->cxld.reset(&cxled->cxld);
192+
goto err;
192193
}
193-
194-
cxled->cxld.reset(&cxled->cxld);
195-
if (i == 0)
196-
return rc;
197-
break;
198194
}
199195

200-
if (i >= p->nr_targets)
201-
return 0;
196+
return 0;
202197

198+
err:
203199
/* undo the targets that were successfully committed */
204200
cxl_region_decode_reset(cxlr, i);
205201
return rc;

0 commit comments

Comments
 (0)