Skip to content

Commit

Permalink
mtd: spi-nor: Separate preparation and locking
Browse files Browse the repository at this point in the history
While this operation will remain a single function call in the end,
let's extract the logic of the [un]prepare calls within their own static
helper. We will soon add new flavors of the *_[un]prepare_and_[un]lock()
helpers, having the preparation logic outside will save us from duplicating
code over and over again.

There is no functional change.

Signed-off-by: Miquel Raynal <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tudor Ambarus <[email protected]>
  • Loading branch information
miquelraynal authored and ambarus committed Mar 29, 2023
1 parent 3204634 commit c154dbd
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions drivers/mtd/spi-nor/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,24 +1070,40 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
}
}

int spi_nor_prep_and_lock(struct spi_nor *nor)
static int spi_nor_prep(struct spi_nor *nor)
{
int ret = 0;

if (nor->controller_ops && nor->controller_ops->prepare)
ret = nor->controller_ops->prepare(nor);

return ret;
}

static void spi_nor_unprep(struct spi_nor *nor)
{
if (nor->controller_ops && nor->controller_ops->unprepare)
nor->controller_ops->unprepare(nor);
}

int spi_nor_prep_and_lock(struct spi_nor *nor)
{
int ret;

ret = spi_nor_prep(nor);
if (ret)
return ret;

mutex_lock(&nor->lock);

return ret;
return 0;
}

void spi_nor_unlock_and_unprep(struct spi_nor *nor)
{
mutex_unlock(&nor->lock);

if (nor->controller_ops && nor->controller_ops->unprepare)
nor->controller_ops->unprepare(nor);
spi_nor_unprep(nor);
}

static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
Expand Down

0 comments on commit c154dbd

Please sign in to comment.