mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fix mtd_part_lock/unlock
@ 2014-07-08  7:37 Zahari Doychev
  2014-07-08  7:37 ` [PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock Zahari Doychev
  0 siblings, 1 reply; 3+ messages in thread
From: Zahari Doychev @ 2014-07-08  7:37 UTC (permalink / raw)
  To: barebox

Hi,

Some mtd drivers does not define lock and unlock partition functions. This
patch avoids crashing when these undefined functions are called from barebox
code e.g. saveenv. Please review this patch and apply it if it is ok.

Thanks


Zahari Doychev (1):
  drivers/mtd: fix NULL pointer dereference in partition lock/unlock

 drivers/mtd/partition.c |    6 ++++++
 1 file changed, 6 insertions(+)

-- 
1.7.9.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock
  2014-07-08  7:37 [PATCH] fix mtd_part_lock/unlock Zahari Doychev
@ 2014-07-08  7:37 ` Zahari Doychev
  2014-07-09  5:31   ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Zahari Doychev @ 2014-07-08  7:37 UTC (permalink / raw)
  To: barebox

Some mtd device does not support lock and unlock functions. Adding this check
avoids crashing when mtd_part_lock/unlock are called for such devices.

Signed-off-by: Zahari Doychev <zahari.doychev@linux.com>
---
 drivers/mtd/partition.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mtd/partition.c b/drivers/mtd/partition.c
index 5c0d46f..5a3d1ae 100644
--- a/drivers/mtd/partition.c
+++ b/drivers/mtd/partition.c
@@ -51,6 +51,9 @@ static int mtd_part_erase(struct mtd_info *mtd, struct erase_info *instr)
 
 static int mtd_part_lock(struct mtd_info *mtd, loff_t offset, size_t len)
 {
+	if (!mtd->master->lock)
+		return -ENOSYS;
+
 	if (!(mtd->flags & MTD_WRITEABLE))
 		return -EROFS;
 
@@ -64,6 +67,9 @@ static int mtd_part_lock(struct mtd_info *mtd, loff_t offset, size_t len)
 
 static int mtd_part_unlock(struct mtd_info *mtd, loff_t offset, size_t len)
 {
+	if (!mtd->master->unlock)
+		return -ENOSYS;
+
 	if (!(mtd->flags & MTD_WRITEABLE))
 		return -EROFS;
 
-- 
1.7.9.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock
  2014-07-08  7:37 ` [PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock Zahari Doychev
@ 2014-07-09  5:31   ` Sascha Hauer
  0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2014-07-09  5:31 UTC (permalink / raw)
  To: Zahari Doychev; +Cc: barebox

On Tue, Jul 08, 2014 at 09:37:35AM +0200, Zahari Doychev wrote:
> Some mtd device does not support lock and unlock functions. Adding this check
> avoids crashing when mtd_part_lock/unlock are called for such devices.
> 
> Signed-off-by: Zahari Doychev <zahari.doychev@linux.com>

Applied, thanks

Sascha

> ---
>  drivers/mtd/partition.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/mtd/partition.c b/drivers/mtd/partition.c
> index 5c0d46f..5a3d1ae 100644
> --- a/drivers/mtd/partition.c
> +++ b/drivers/mtd/partition.c
> @@ -51,6 +51,9 @@ static int mtd_part_erase(struct mtd_info *mtd, struct erase_info *instr)
>  
>  static int mtd_part_lock(struct mtd_info *mtd, loff_t offset, size_t len)
>  {
> +	if (!mtd->master->lock)
> +		return -ENOSYS;
> +
>  	if (!(mtd->flags & MTD_WRITEABLE))
>  		return -EROFS;
>  
> @@ -64,6 +67,9 @@ static int mtd_part_lock(struct mtd_info *mtd, loff_t offset, size_t len)
>  
>  static int mtd_part_unlock(struct mtd_info *mtd, loff_t offset, size_t len)
>  {
> +	if (!mtd->master->unlock)
> +		return -ENOSYS;
> +
>  	if (!(mtd->flags & MTD_WRITEABLE))
>  		return -EROFS;
>  
> -- 
> 1.7.9.5
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-09  5:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-08  7:37 [PATCH] fix mtd_part_lock/unlock Zahari Doychev
2014-07-08  7:37 ` [PATCH] drivers/mtd: fix NULL pointer dereference in partition lock/unlock Zahari Doychev
2014-07-09  5:31   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox