Re: [PATCH] blkcg: add sanity check for blkcg policy operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 11, 2017 at 12:00:55AM +0800, weiping zhang wrote:
> + * blkcg_policy_check_ops - check policy's operations
> + * @pol: blkcg policy to check
> + *
> + * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs.
> + * Return true on success and false on failure.
> + */
> +static bool blkcg_policy_check_ops(struct blkcg_policy *pol)
> +{
> +	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
> +		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
> +		return false;
> +
> +	if ((pol->pd_alloc_fn && !pol->pd_free_fn) ||
> +		(!pol->pd_alloc_fn && pol->pd_free_fn))
> +		return false;
> +
> +	return true;
> +}
> +
> +/**
>   * blkcg_policy_register - register a blkcg policy
>   * @pol: blkcg policy to register
>   *
> @@ -1419,6 +1439,9 @@ int blkcg_policy_register(struct blkcg_policy *pol)
>  	if (i >= BLKCG_MAX_POLS)
>  		goto err_unlock;
>  
> +	if (!blkcg_policy_check_ops(pol))
> +		goto err_unlock;
> +

Can you merge it into the caller?

+	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
+		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
+		goto err_unlock;
+
+	if ((pol->pd_alloc_fn && !pol->pd_free_fn) ||
+		(!pol->pd_alloc_fn && pol->pd_free_fn))
+		goto err_unlock;



-- 
Johannes Thumshirn                                          Storage
jthumshirn@xxxxxxx                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux