diff mbox series

[01/16] block: sed-opal: fix IOC_OPAL_ENABLE_DISABLE_MBR

Message ID 1550103368-4605-2-git-send-email-zub@linux.fjfi.cvut.cz (mailing list archive)
State New, archived
Headers show
Series sed-opal: fix shadow MBR enable/disable and clean up code | expand

Commit Message

David Kozub Feb. 14, 2019, 12:15 a.m. UTC
The implementation of IOC_OPAL_ENABLE_DISABLE_MBR handled the value
opal_mbr_data.enable_disable incorrectly: enable_disable is expected
to be one of OPAL_MBR_ENABLE(0) or OPAL_MBR_DISABLE(1). enable_disable
was passed directly to set_mbr_done and set_mbr_enable_disable where
is was interpreted as either OPAL_TRUE(1) or OPAL_FALSE(0). The end
result was that calling IOC_OPAL_ENABLE_DISABLE_MBR with OPAL_MBR_ENABLE
actually disabled the shadow MBR and vice versa.

This patch adds correct conversion from OPAL_MBR_DISABLE/ENABLE to
OPAL_FALSE/TRUE. The change affects existing programs using
IOC_OPAL_ENABLE_DISABLE_MBR but this is typically used only once when
setting up an Opal drive.

Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
Acked-by: Jon Derrick <jonathan.derrick@intel.com>
---
 block/sed-opal.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Christoph Hellwig March 28, 2019, 5:04 p.m. UTC | #1
Reviewed-by: Christoph Hellwig <hch@lst.de>
Scott Bauer April 6, 2019, 3:15 p.m. UTC | #2
On Thu, Feb 14, 2019 at 01:15:53AM +0100, David Kozub wrote:
> The implementation of IOC_OPAL_ENABLE_DISABLE_MBR handled the value
> opal_mbr_data.enable_disable incorrectly: enable_disable is expected
> to be one of OPAL_MBR_ENABLE(0) or OPAL_MBR_DISABLE(1). enable_disable
> was passed directly to set_mbr_done and set_mbr_enable_disable where
> is was interpreted as either OPAL_TRUE(1) or OPAL_FALSE(0). The end
> result was that calling IOC_OPAL_ENABLE_DISABLE_MBR with OPAL_MBR_ENABLE
> actually disabled the shadow MBR and vice versa.
> 
> This patch adds correct conversion from OPAL_MBR_DISABLE/ENABLE to
> OPAL_FALSE/TRUE. The change affects existing programs using
> IOC_OPAL_ENABLE_DISABLE_MBR but this is typically used only once when
> setting up an Opal drive.
> 
> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz>
> Acked-by: Jon Derrick <jonathan.derrick@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Scott Bauer <sbauer@plzdonthack.me>
diff mbox series

Patch

diff --git a/block/sed-opal.c b/block/sed-opal.c
index e0de4dd448b3..119640897293 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -2095,13 +2095,16 @@  static int opal_erase_locking_range(struct opal_dev *dev,
 static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
 					  struct opal_mbr_data *opal_mbr)
 {
+	u8 enable_disable = opal_mbr->enable_disable == OPAL_MBR_ENABLE ?
+		OPAL_TRUE : OPAL_FALSE;
+
 	const struct opal_step mbr_steps[] = {
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
-		{ set_mbr_done, &opal_mbr->enable_disable },
+		{ set_mbr_done, &enable_disable },
 		{ end_opal_session, },
 		{ start_admin1LSP_opal_session, &opal_mbr->key },
-		{ set_mbr_enable_disable, &opal_mbr->enable_disable },
+		{ set_mbr_enable_disable, &enable_disable },
 		{ end_opal_session, },
 		{ NULL, }
 	};
@@ -2221,7 +2224,7 @@  static int __opal_lock_unlock(struct opal_dev *dev,
 
 static int __opal_set_mbr_done(struct opal_dev *dev, struct opal_key *key)
 {
-	u8 mbr_done_tf = 1;
+	u8 mbr_done_tf = OPAL_TRUE;
 	const struct opal_step mbrdone_step [] = {
 		{ opal_discovery0, },
 		{ start_admin1LSP_opal_session, key },