Re: [PATCH] jfs: Add missing NULL pointer check in __get_metapage

Juerg Haefliger <[email protected]>
Newsgroups gmane.comp.file-systems.jfs.general
Message-ID <1dbf4a54-968f-0ca7-da96-e262c653fecb__777.531628455286$1508917873$gmane$org@canonical.com>
Is this a patch you might consider?

Thanks
...Juerg


On 10/04/2017 10:24 AM, Juerg Haefliger wrote:
> alloc_metapage can return a NULL pointer so check for that. And also emit
> an error message if that happens.
> 
> Signed-off-by: Juerg Haefliger <[email protected]>
> ---
>  fs/jfs/jfs_metapage.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
> index 1c4b9ad4d7ab..00f21af66872 100644
> --- a/fs/jfs/jfs_metapage.c
> +++ b/fs/jfs/jfs_metapage.c
> @@ -187,14 +187,18 @@ static inline struct metapage *alloc_metapage(gfp_t gfp_mask)
>  {
>  	struct metapage *mp = mempool_alloc(metapage_mempool, gfp_mask);
>  
> -	if (mp) {
> -		mp->lid = 0;
> -		mp->lsn = 0;
> -		mp->data = NULL;
> -		mp->clsn = 0;
> -		mp->log = NULL;
> -		init_waitqueue_head(&mp->wait);
> +	if (!mp) {
> +		jfs_err("mempool_alloc failed!\n");
> +		return NULL;
>  	}
> +
> +	mp->lid = 0;
> +	mp->lsn = 0;
> +	mp->data = NULL;
> +	mp->clsn = 0;
> +	mp->log = NULL;
> +	init_waitqueue_head(&mp->wait);
> +
>  	return mp;
>  }
>  
> @@ -663,6 +667,8 @@ struct metapage *__get_metapage(struct inode *inode, unsigned long lblock,
>  	} else {
>  		INCREMENT(mpStat.pagealloc);
>  		mp = alloc_metapage(GFP_NOFS);
> +		if (!mp)
> +			goto unlock;
>  		mp->page = page;
>  		mp->sb = inode->i_sb;
>  		mp->flag = 0;
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Jfs-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jfs-discussion
signature.asc (application/pgp-signature, 845 B)
-----BEGIN PGP SIGNATURE-----

iQI7BAEBCAAlBQJZ8EJMHhxqdWVyZy5oYWVmbGlnZXJAY2Fub25pY2FsLmNvbQAK
CRB1TDqW+fi0jAuoD/9beZSLeWzOEhBzYqhowE+RILY/N9v7E5KnRXC+VC/OpQ6m
S8s35S8wPbh19LhbYSpn+JZXcmgeBoRZV/VqCr7yXh9L2qA45RxQGs5ASm0Gel92
UTrdTm+WEyMcQWO91z4BcjPuPxutBA3aSiBocqxq8vpjS0jydP5aJG3YBT9gX59f
dM11O9xWjfW8DuV0ProwNav/lOHOzLpulunvd0HfVfNLPUYu4thBMGAzyFRQ4f58
a+ePJGfJovY7ldcIycyFa/ogoVjCBGDT2HKkHsjH/YI6M9fZTDL6/0oA2XM3Wxc5
psqks0zk5POAoLeAYK859DbPHsuAvW/VzCdzPtxmVfDcy+FRCTFwpSVQO1aqV68o
ZfDhdWyLB9f5l3K9/RWs0S4VyGhukLV+FKUioICZizhKuXB85NEL9bSSEglM7M3y
ntcxYns8mB3BVWfD7muPGWk7RbO9QM3aHoGZVVFEqZrGlmR6jExV+L2HM77K0c7J
RguT8WsIAezHwDczMrrOXUJIt171C4LOVPzkTLVoJQstSMxmqPBsI6t9dfHB5/Gz
ysFE4MVoYszeIUo5mIgxr+yV5T+YTc/v9fuNEwaRtI7ytaksFiHOFj7wcq4z1ncx
F4hFSowsOFM3VvfAefzEVx+lOouTdplF0hRTS8WgB2wlGtR63gsS8a2VER1Zfg==
=eoyn
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.