Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6457309ybh; Thu, 8 Aug 2019 00:19:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoyZ2QUk2+vopBEltaI/Puir3KU/ZQq/5O6FxkBcDhHB8LGLIYjPfNt91C7HDzNJOp6qsd X-Received: by 2002:a17:902:6b44:: with SMTP id g4mr12236033plt.152.1565248760205; Thu, 08 Aug 2019 00:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565248760; cv=none; d=google.com; s=arc-20160816; b=GifWHmRZGor9Hcu8BcbaDZPdfb8iTibnhBCWf1u9Jixj0GSHrwUKJzBL3o7jLH7m2y tk20EOXdAMvvNQu65XSBB0wMF4b1int3TPJhM9JcS365e2tRH/Y0Iyz1qavpCGBLvjDt wNCPIZ0qfP8j3KSA3Z49uSjQ936Yt0SZSbskswUTURBr/UyNzRwtyJOekFKzWjkBefCv Ly1Y3v9q/z10WWkE8VQyMb49yCIprKJkB0esycHrP4/nSAAnBgp2dpKA8xWUR/1ehZcW MRQXRWhTVAJjo2M9r5AbnMKS1M05UOU7B713oB12qzhtHvpgqAaEE94HniuEIjweV2BH vU/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=1zFoSskzKCZlza0GblOaMNM1s/A9U+UElWzjCW1f3zM=; b=ibi59Fy1y0uNr4dH0LrPkI9pGccroLhlJD9uZUJSDO9W6rEdTUYe0eZbhMOxmSrzvg ajXshjP0CtojNXgtVXelhVaU4zB6b1xp7xQFZNPqab6s0Ct/JctZ9jGysoLOddEyLD/f 51lreX5O2B2+FGjgzt2kWSrHU5LUre8rK2eejm5ha+P/+3EJlWnRTm7pZwlCigqoDS31 sRkW9d0CdII5cNcttF5xx3QeBWnXLz1PPeV/hACWpY/6SrstvpsVdC4t7erHxgKxcG/6 9j2HyOmvKKXrDoOeUq4WVR2CWc7q/IehPaXD1Va+R8g+0M6auo0wgz0dyZTM7iziktYj N2Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=oJHYnIJo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a19si42918384pgv.180.2019.08.08.00.19.04; Thu, 08 Aug 2019 00:19:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=oJHYnIJo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731394AbfHHHSX (ORCPT + 99 others); Thu, 8 Aug 2019 03:18:23 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39185 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbfHHHSX (ORCPT ); Thu, 8 Aug 2019 03:18:23 -0400 Received: by mail-pg1-f194.google.com with SMTP id u17so43563260pgi.6; Thu, 08 Aug 2019 00:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1zFoSskzKCZlza0GblOaMNM1s/A9U+UElWzjCW1f3zM=; b=oJHYnIJo3jEzpDKrzYDhX1SzasWKocag1r5XRvIt88IMD9VZxELPtyWRZbPrxJbMsr cKnNgsMc6MtGX68Me2qsU1DUZPFPnBM5WnPhgQLoMkIfbJlCqWcx1FcVZIWbZg03gXJI epDDEBbZLL4rWkLp3dE6HEeytQu12R1V78WnshG96d61iLI6aUOQLdxYrj7syVia/0t0 8j7x2yRT6xUXeFn47tCFFcf6cDihBHcLpgj/JRPNWWadH4h6W1qsqmNYZ3u1/gpHCLJB /F2+JJdA8nQLwYptc8rkmu08739CqCuxpH7aUINSUZsbrtVELL+jjorB+q+VZJjjoH4r khdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1zFoSskzKCZlza0GblOaMNM1s/A9U+UElWzjCW1f3zM=; b=fMqZiS1LUsn0zJWfQytJip+Sr8wl7RtleodOB2JUb8Dx7gsbexEa5jJv1mg8E4wZqU FV9JY/qdyLXBEz5b0F3kBezp+4l0VaDdJcGq3HYw1l7WD7k2txk96/+g4lm600y7esaQ /AB+PBLyvMg92psAjLL0oQuH3U1LdnUZUoecZn3Wy5uYEO0Xzu11fRzZMCKPKjFgy4kD yUFrZhRgxDi7+UniJrcyRDd7T6RmNMaov/5YXWlGpYZRTKfX+8LJf5Ct84CNff/FLUC2 1kb5UP6TqjC/xBwFo7BbZvqnbUfSKieFQ4VpR9OswkU7zcOuCVK7JSA/k5VmZ7LLl1gl u9Kg== X-Gm-Message-State: APjAAAV3MERy+Y3UHEV/RCvi0f4DCIZ9bx3A3GG4GUnNliZoL3nPjP9D e3WVvU/frDuyY9JonyOez51UBCPspXojOQ== X-Received: by 2002:a17:90a:360b:: with SMTP id s11mr2520806pjb.51.1565248702541; Thu, 08 Aug 2019 00:18:22 -0700 (PDT) Received: from suzukaze.ipads-lab.se.sjtu.edu.cn ([89.31.126.54]) by smtp.gmail.com with ESMTPSA id s20sm105514644pfe.169.2019.08.08.00.18.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 00:18:21 -0700 (PDT) From: Chuhong Yuan Cc: Heiko Carstens , Vasily Gorbik , Christian Borntraeger , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Chuhong Yuan Subject: [PATCH 1/2] s390/extmem: Use refcount_t for refcount Date: Thu, 8 Aug 2019 15:18:17 +0800 Message-Id: <20190808071817.6595-1-hslester96@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Reference counters are preferred to use refcount_t instead of atomic_t. This is because the implementation of refcount_t can prevent overflows and detect possible use-after-free. So convert atomic_t ref counters to refcount_t. Signed-off-by: Chuhong Yuan --- arch/s390/mm/extmem.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c index 0b5622714c12..78e801287c72 100644 --- a/arch/s390/mm/extmem.c +++ b/arch/s390/mm/extmem.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -64,7 +65,7 @@ struct dcss_segment { char res_name[16]; unsigned long start_addr; unsigned long end; - atomic_t ref_count; + refcount_t ref_count; int do_nonshared; unsigned int vm_segtype; struct qrange range[6]; @@ -362,7 +363,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long seg->start_addr = start_addr; seg->end = end_addr; seg->do_nonshared = do_nonshared; - atomic_set(&seg->ref_count, 1); + refcount_set(&seg->ref_count, 1); list_add(&seg->list, &dcss_list); *addr = seg->start_addr; *end = seg->end; @@ -422,7 +423,7 @@ segment_load (char *name, int do_nonshared, unsigned long *addr, rc = __segment_load (name, do_nonshared, addr, end); else { if (do_nonshared == seg->do_nonshared) { - atomic_inc(&seg->ref_count); + refcount_inc(&seg->ref_count); *addr = seg->start_addr; *end = seg->end; rc = seg->vm_segtype; @@ -468,7 +469,7 @@ segment_modify_shared (char *name, int do_nonshared) rc = 0; goto out_unlock; } - if (atomic_read (&seg->ref_count) != 1) { + if (refcount_read(&seg->ref_count) != 1) { pr_warn("DCSS %s is in use and cannot be reloaded\n", name); rc = -EAGAIN; goto out_unlock; @@ -544,7 +545,7 @@ segment_unload(char *name) pr_err("Unloading unknown DCSS %s failed\n", name); goto out_unlock; } - if (atomic_dec_return(&seg->ref_count) != 0) + if (!refcount_dec_and_test(&seg->ref_count)) goto out_unlock; release_resource(seg->res); kfree(seg->res); -- 2.20.1