cxl/core: fix test_bit misuse with CXL_DECODER_F_ bitmask flags
PATCH 1/1 cxl/core: fix test_bit misuse with CXL_DECODER_F_ bitmask flags
CXL_DECODER_F_LOCK (BIT(4) = 16) and CXL_DECODER_F_NORMALIZED_ADDRESSING (BIT(6) = 64) are bit masks, but three call sites pass them to test_bit() which expects a bit number.
Replace test_bit() with direct bitmask tests, consistent with every other use of these flags.
--- drivers/cxl/core/hdm.c | 2 +- drivers/cxl/core/region.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +1 -1
@@ -904,7 +904,7 @@ static void cxl_decoder_reset(struct cxl_decoder *cxld)if ((cxld->flags &CXL_DECODER_F_ENABLE ) ==0 )return ; -if (test_bit (CXL_DECODER_F_LOCK , &cxld->flags)) +if (cxld->flags &CXL_DECODER_F_LOCK )return ;if (port->commit_end == id)
drivers/cxl/core/region.c +2 -2
@@ -1100,12 +1100,12 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,static void cxl_region_setup_flags (struct cxl_region *cxlr,struct cxl_decoder *cxld) { -if (test_bit (CXL_DECODER_F_LOCK , &cxld->flags)) { +if (cxld->flags &CXL_DECODER_F_LOCK ) {set_bit (CXL_REGION_F_LOCK , &cxlr->flags);clear_bit (CXL_REGION_F_NEEDS_RESET , &cxlr->flags); } -if (test_bit (CXL_DECODER_F_NORMALIZED_ADDRESSING , &cxld->flags)) +if (cxld->flags &CXL_DECODER_F_NORMALIZED_ADDRESSING )set_bit (CXL_REGION_F_NORMALIZED_ADDRESSING , &cxlr->flags); }
Signature · 1 line
2.53.0
Quoted 9 lines · Gregory Price
CXL_DECODER_F_LOCK(BIT(4) = 16) andCXL_DECODER_F_NORMALIZED_ADDRESSING(BIT(6) = 64) are bit masks, but three call sites pass them totest_bit()which expects a bit number.Replace
test_bit()with direct bitmask tests, consistent with every other use of these flags.Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")Signed-off-by Gregory Price <[email protected]>
Alison sent out a patch [1] two weeks ago for this. I suspect you found this bug independently, so I figured I should point it out. Otherwise, I would add a Reported-by (or some other tag) with her name.
Thanks,
Ben
[1]: https://lore.kernel.org/linux-cxl/[email protected]/
Quoted 37 lines
--- drivers/cxl/core/hdm.c | 2 +- drivers/cxl/core/region.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)drivers/cxl/core/hdm.c +1
-1@@ -904,7 +904,7 @@ static void cxl_decoder_reset(struct cxl_decoder *cxld)if ((cxld->flags &CXL_DECODER_F_ENABLE ) ==0 )return ; -if (test_bit (CXL_DECODER_F_LOCK , &cxld->flags)) +if (cxld->flags &CXL_DECODER_F_LOCK )return ;if (port->commit_end == id)drivers/cxl/core/region.c +2
-2@@ -1100,12 +1100,12 @@ static int cxl_rr_assign_decoder(struct cxl_port *port, struct cxl_region *cxlr,static void cxl_region_setup_flags (struct cxl_region *cxlr,struct cxl_decoder *cxld) { -if (test_bit (CXL_DECODER_F_LOCK , &cxld->flags)) { +if (cxld->flags &CXL_DECODER_F_LOCK ) {set_bit (CXL_REGION_F_LOCK , &cxlr->flags);clear_bit (CXL_REGION_F_NEEDS_RESET , &cxlr->flags); } -if (test_bit (CXL_DECODER_F_NORMALIZED_ADDRESSING , &cxld->flags)) +if (cxld->flags &CXL_DECODER_F_NORMALIZED_ADDRESSING )set_bit (CXL_REGION_F_NORMALIZED_ADDRESSING , &cxlr->flags); }
Quoted 11 lines · Benjamin
Quoted 9 lines · Gregory Price
CXL_DECODER_F_LOCK(BIT(4) = 16) andCXL_DECODER_F_NORMALIZED_ADDRESSING(BIT(6) = 64) are bit masks, but three call sites pass them totest_bit()which expects a bit number.Replace
test_bit()with direct bitmask tests, consistent with every other use of these flags.Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")Signed-off-by Gregory Price <[email protected]>
Quoted 8 lines
Alison sent out a patch [1] two weeks ago for this. I suspect you found this bug independently, so I figured I should point it out. Otherwise, I would add a Reported-by (or some other tag) with her name.
Thanks,
Ben
Ah, yeah, missed this, and did find independently when testing unbinds.
Wasn't on cxl/next so I thought it hadn't been found yet.
Cool, thanks!
~Gregory
Dave Jiang
maintainerQuoted 16 lines · Gregory Price
Quoted 15 lines · Benjamin
Quoted 9 lines · Gregory Price
CXL_DECODER_F_LOCK(BIT(4) = 16) andCXL_DECODER_F_NORMALIZED_ADDRESSING(BIT(6) = 64) are bit masks, but three call sites pass them totest_bit()which expects a bit number.Replace
test_bit()with direct bitmask tests, consistent with every other use of these flags.Fixes 2230c4bdc412 ("cxl: Add handling of locked CXL decoder")Signed-off-by Gregory Price <[email protected]>Alison sent out a patch [1] two weeks ago for this. I suspect you found this bug independently, so I figured I should point it out. Otherwise, I would add a Reported-by (or some other tag) with her name.
Quoted 8 lines
Quoted 4 lines
Thanks,
BenAh, yeah, missed this, and did find independently when testing unbinds.
Wasn't on cxl/next so I thought it hadn't been found yet.
Yeah waiting on 7.0-rc1 for cxl/fixes. I also asked her to split the patches into 2 fixes. But if you don't mind go add your review tag that'd be great! :)
Quoted 3 lines
Cool, thanks!
~Gregory