* [PATCH 1/2] zram: avoid null access when fail to alloc meta @ 2014-02-25 1:08 Minchan Kim 2014-02-25 1:08 ` [PATCH 2/2] zram: delete zram_init_device() function Minchan Kim 2014-02-25 9:37 ` [PATCH 1/2] zram: avoid null access when fail to alloc meta Jerome Marchand 0 siblings, 2 replies; 4+ messages in thread From: Minchan Kim @ 2014-02-25 1:08 UTC (permalink / raw) To: Andrew Morton Cc: Nitin Gupta, Jerome Marchand, Sergey Senozhatsky, linux-kernel, Minchan Kim, stable zram_meta_alloc could be failed so caller should check it. Otherwise, your system will be hang. Cc: <stable@vger.kernel.org> Signed-off-by: Minchan Kim <minchan@kernel.org> --- drivers/block/zram/zram_drv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 5ec61be793d2..21aee3edcb25 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -554,6 +554,8 @@ static ssize_t disksize_store(struct device *dev, disksize = PAGE_ALIGN(disksize); meta = zram_meta_alloc(disksize); + if (!meta) + return -ENOMEM; down_write(&zram->init_lock); if (init_done(zram)) { up_write(&zram->init_lock); -- 1.8.5.3 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] zram: delete zram_init_device() function 2014-02-25 1:08 [PATCH 1/2] zram: avoid null access when fail to alloc meta Minchan Kim @ 2014-02-25 1:08 ` Minchan Kim 2014-02-25 10:51 ` Jerome Marchand 2014-02-25 9:37 ` [PATCH 1/2] zram: avoid null access when fail to alloc meta Jerome Marchand 1 sibling, 1 reply; 4+ messages in thread From: Minchan Kim @ 2014-02-25 1:08 UTC (permalink / raw) To: Andrew Morton Cc: Nitin Gupta, Jerome Marchand, Sergey Senozhatsky, linux-kernel, Minchan Kim From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> allocate new `zram_meta' in disksize_store() only for uninitialised zram device, saving a number of allocations and deallocations in case if disksize_store() was called on currently used device. at the same time zram_meta stack variable is not necessary, because we can set ->meta directly. there is also no need in setting QUEUE_FLAG_NONROT queue on every disksize_store(), set it once during device creation. [minchan@kernel.org]: handled zram->meta alloc fail case. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Minchan Kim <minchan@kernel.org> --- drivers/block/zram/zram_drv.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 21aee3edcb25..9baac5b76bfe 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -533,40 +533,32 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) up_write(&zram->init_lock); } -static void zram_init_device(struct zram *zram, struct zram_meta *meta) -{ - /* zram devices sort of resembles non-rotational disks */ - queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); - zram->meta = meta; - pr_debug("Initialization done!\n"); -} - static ssize_t disksize_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { u64 disksize; - struct zram_meta *meta; struct zram *zram = dev_to_zram(dev); disksize = memparse(buf, NULL); if (!disksize) return -EINVAL; - disksize = PAGE_ALIGN(disksize); - meta = zram_meta_alloc(disksize); - if (!meta) - return -ENOMEM; down_write(&zram->init_lock); if (init_done(zram)) { up_write(&zram->init_lock); - zram_meta_free(meta); pr_info("Cannot change disksize for initialized device\n"); return -EBUSY; } + disksize = PAGE_ALIGN(disksize); + zram->meta = zram_meta_alloc(disksize); + if (!zram->meta) { + up_write(&zram->init_lock); + return -ENOMEM; + } + zram->disksize = disksize; set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); - zram_init_device(zram, meta); up_write(&zram->init_lock); return len; @@ -776,7 +768,8 @@ static int create_device(struct zram *zram, int device_id) /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ set_capacity(zram->disk, 0); - + /* zram devices sort of resembles non-rotational disks */ + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); /* * To ensure that we always get PAGE_SIZE aligned * and n*PAGE_SIZED sized I/O requests. -- 1.8.5.3 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] zram: delete zram_init_device() function 2014-02-25 1:08 ` [PATCH 2/2] zram: delete zram_init_device() function Minchan Kim @ 2014-02-25 10:51 ` Jerome Marchand 0 siblings, 0 replies; 4+ messages in thread From: Jerome Marchand @ 2014-02-25 10:51 UTC (permalink / raw) To: Minchan Kim; +Cc: Andrew Morton, Nitin Gupta, Sergey Senozhatsky, linux-kernel On 02/25/2014 02:08 AM, Minchan Kim wrote: > From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> > > allocate new `zram_meta' in disksize_store() only for uninitialised > zram device, saving a number of allocations and deallocations in case > if disksize_store() was called on currently used device. at the same > time zram_meta stack variable is not necessary, because we can set > ->meta directly. there is also no need in setting QUEUE_FLAG_NONROT > queue on every disksize_store(), set it once during device creation. > > [minchan@kernel.org]: handled zram->meta alloc fail case. > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> > Signed-off-by: Minchan Kim <minchan@kernel.org> Acked-by: Jerome Marchand <jmarchan@redhat.com> > --- > drivers/block/zram/zram_drv.c | 25 +++++++++---------------- > 1 file changed, 9 insertions(+), 16 deletions(-) > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index 21aee3edcb25..9baac5b76bfe 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -533,40 +533,32 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity) > up_write(&zram->init_lock); > } > > -static void zram_init_device(struct zram *zram, struct zram_meta *meta) > -{ > - /* zram devices sort of resembles non-rotational disks */ > - queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); > - zram->meta = meta; > - pr_debug("Initialization done!\n"); > -} > - > static ssize_t disksize_store(struct device *dev, > struct device_attribute *attr, const char *buf, size_t len) > { > u64 disksize; > - struct zram_meta *meta; > struct zram *zram = dev_to_zram(dev); > > disksize = memparse(buf, NULL); > if (!disksize) > return -EINVAL; > > - disksize = PAGE_ALIGN(disksize); > - meta = zram_meta_alloc(disksize); > - if (!meta) > - return -ENOMEM; > down_write(&zram->init_lock); > if (init_done(zram)) { > up_write(&zram->init_lock); > - zram_meta_free(meta); > pr_info("Cannot change disksize for initialized device\n"); > return -EBUSY; > } > > + disksize = PAGE_ALIGN(disksize); > + zram->meta = zram_meta_alloc(disksize); > + if (!zram->meta) { > + up_write(&zram->init_lock); > + return -ENOMEM; > + } > + > zram->disksize = disksize; > set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); > - zram_init_device(zram, meta); > up_write(&zram->init_lock); > > return len; > @@ -776,7 +768,8 @@ static int create_device(struct zram *zram, int device_id) > > /* Actual capacity set using syfs (/sys/block/zram<id>/disksize */ > set_capacity(zram->disk, 0); > - > + /* zram devices sort of resembles non-rotational disks */ > + queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue); > /* > * To ensure that we always get PAGE_SIZE aligned > * and n*PAGE_SIZED sized I/O requests. > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] zram: avoid null access when fail to alloc meta 2014-02-25 1:08 [PATCH 1/2] zram: avoid null access when fail to alloc meta Minchan Kim 2014-02-25 1:08 ` [PATCH 2/2] zram: delete zram_init_device() function Minchan Kim @ 2014-02-25 9:37 ` Jerome Marchand 1 sibling, 0 replies; 4+ messages in thread From: Jerome Marchand @ 2014-02-25 9:37 UTC (permalink / raw) To: Minchan Kim Cc: Andrew Morton, Nitin Gupta, Sergey Senozhatsky, linux-kernel, stable On 02/25/2014 02:08 AM, Minchan Kim wrote: > zram_meta_alloc could be failed so caller should check it. > Otherwise, your system will be hang. > > Cc: <stable@vger.kernel.org> > Signed-off-by: Minchan Kim <minchan@kernel.org> Acked-by: Jerome Marchand <jmarchan@redhat.com> > --- > drivers/block/zram/zram_drv.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c > index 5ec61be793d2..21aee3edcb25 100644 > --- a/drivers/block/zram/zram_drv.c > +++ b/drivers/block/zram/zram_drv.c > @@ -554,6 +554,8 @@ static ssize_t disksize_store(struct device *dev, > > disksize = PAGE_ALIGN(disksize); > meta = zram_meta_alloc(disksize); > + if (!meta) > + return -ENOMEM; > down_write(&zram->init_lock); > if (init_done(zram)) { > up_write(&zram->init_lock); > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-25 10:51 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-02-25 1:08 [PATCH 1/2] zram: avoid null access when fail to alloc meta Minchan Kim 2014-02-25 1:08 ` [PATCH 2/2] zram: delete zram_init_device() function Minchan Kim 2014-02-25 10:51 ` Jerome Marchand 2014-02-25 9:37 ` [PATCH 1/2] zram: avoid null access when fail to alloc meta Jerome Marchand
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox