From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14DDB3A7839 for ; Tue, 12 May 2026 09:10:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778577054; cv=none; b=ZUFd8h1drgu90EqkZLw7DpgkXI7x6CkliCLcy4+wr3IB2kHEWO6dcVY03DCU2abjL4evFBMxTFbZaXIXOms1A4kHd/qonXtZFxM0/0FCWpFbnkwH43nW+LoQjxqg8aCkSM1vmtVpEkt3m/aUi3rmqfbN+Cctlbt+Jfg6mWTm17w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778577054; c=relaxed/simple; bh=zWRK46qZUHhdH0Nao8NSI++FIT89N57wcDbJUpLovHA=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=UXcJ8gLScnAhmyAusGesoy2U/tyiTiMsM/6MIch69JaCeDAr+NiYK/amY9yGleZaxsztv1NTum8uFB+9iVdZZPUDErHVOgEr5ZU1g5EyZ7vR2N47KUj7slyRdHL3TJNtYdesvPgvU2sLPkbZphFV2jCHUUs5oEHdtQyw/Nz6/X4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DCEI6cgF; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DCEI6cgF" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778577048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pW8xb3lQZVwG9SPYcBLdpX+LoLXqJR9Zj/QEZ6SgtRo=; b=DCEI6cgF8YTaTCzw0zinvY1W92ic6asXnK56XhZkup4/a28KDmF0oYQEJj3THM+U9U5nOk geaZFAsavVFIChzY3Talo18o5WQ4YSjJI87UkQjqwubEP465K8vXmJsoPgYvqG9WqSVPUI E0CSaq9JZZ5RpEZI5OwVYDL7i42EnmM= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.500.181\)) Subject: Re: [PATCH v1] mm/shrinker: simplify shrinker_memcg_alloc() using guard() X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20260512085546.368911-1-18810879172@163.com> Date: Tue, 12 May 2026 17:10:03 +0800 Cc: akpm@linux-foundation.org, david@fromorbit.com, qi.zheng@linux.dev, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, wangxuewen Content-Transfer-Encoding: quoted-printable Message-Id: <616E5E26-BB36-43CD-B086-0F238903B1BF@linux.dev> References: <20260512085546.368911-1-18810879172@163.com> To: wangxuewen <18810879172@163.com> X-Migadu-Flow: FLOW_OUT > On May 12, 2026, at 16:55, wangxuewen <18810879172@163.com> wrote: >=20 > Use guard(mutex) to automatically handle shrinker_mutex locking and > unlocking in shrinker_memcg_alloc(). This removes the explicit > mutex_unlock() call, the goto-based error path, and the redundant > ret variable, resulting in cleaner and more concise code. >=20 > Signed-off-by: wangxuewen > --- > mm/shrinker.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) >=20 > diff --git a/mm/shrinker.c b/mm/shrinker.c > index 76b3f750cf65..1274130323bf 100644 > --- a/mm/shrinker.c > +++ b/mm/shrinker.c > @@ -222,22 +222,19 @@ static int shrinker_memcg_alloc(struct shrinker = *shrinker) > if (mem_cgroup_kmem_disabled() && !(shrinker->flags & = SHRINKER_NONSLAB)) > return -ENOSYS; >=20 > - mutex_lock(&shrinker_mutex); > + guard(mutex)(&shrinker_mutex); > id =3D idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); > if (id < 0) > - goto unlock; > + return id; >=20 > if (id >=3D shrinker_nr_max) { > if (expand_shrinker_info(id)) { > idr_remove(&shrinker_idr, id); > - goto unlock; > + return -ENOMEM; > } > } > shrinker->id =3D id; > - ret =3D 0; > -unlock: > - mutex_unlock(&shrinker_mutex); > - return ret; One small thing: since ret is no longer used after this change, it should be dropped from the declaration to avoid an unused-variable warning: - int id, ret =3D -ENOMEM; + int id; Otherwise looks good to me. Thanks, Muchun > + return 0; > } >=20 > static void shrinker_memcg_remove(struct shrinker *shrinker) > --=20 > 2.25.1 >=20