diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 2d73297003d2..11f59bc2db8e 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -752,6 +752,10 @@ static int z_erofs_register_pcluster(struct z_erofs_frontend *fe) lockref_init(&pcl->lockref); /* one ref for this request */ pcl->algorithmformat = map->m_algorithmformat; + if (pcl->algorithmformat >= Z_EROFS_COMPRESSION_MAX) { + err = -EINVAL; + goto out; + } pcl->pclustersize = map->m_plen; pcl->length = 0; pcl->partial = true; @@ -796,6 +800,7 @@ static int z_erofs_register_pcluster(struct z_erofs_frontend *fe) err_out: mutex_unlock(&pcl->lock); +out: z_erofs_free_pcluster(pcl); return err; }