From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0D97C48BCF for ; Wed, 9 Jun 2021 15:31:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A149360FF0 for ; Wed, 9 Jun 2021 15:31:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A149360FF0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RIEA6oR7JzwrUTkr/tmZMiyjH9iApmTfRzJjQTr4y0A=; b=2XbGJEC2RlLQkhV/g+Y0QKdPbN CTCR0x5BukcM1lqbZhAcAUrlBPzQaujq79hYtjUK2J0Wy+LZribOSBGrdUYnjss/SQq9PZdpz9UJ8 mnklz1q3ifZMnxabjLOg9uLTH5x4TPrYFWIiAxom0XYDFk6vFy8sFpQsFO0bcLsVXKceLpzOuZu5i FG5iyE7vX+OGU/SH0GWlokj6fg9HJ1H66Ab2Khtf0uLR03/inKzkTc/SfYpJ9US6hJ7PPDQr/cDVs nx1EX0wJXHvDHN2TXX4DIP6S7sseY4AtfEVu8yL3w9M6zOkwKU4zE8B8cQFWVNuXr2v376MDc+JPZ I60fK4yQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lr08m-00EbDA-0b; Wed, 09 Jun 2021 15:29:13 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqz13-00EFqc-O8 for linux-arm-kernel@lists.infradead.org; Wed, 09 Jun 2021 14:17:11 +0000 Received: by mail-pj1-x1031.google.com with SMTP id mp5-20020a17090b1905b029016dd057935fso1460592pjb.5 for ; Wed, 09 Jun 2021 07:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=xN7KEYZ9pR7gVi6zMi8zHdassp7hlEpZ4bgzEC5iNSM=; b=JT5NvdDCeF8FD9cSAojvj7dEMlD7WmGflpowWODnivNMkQhFDCtjpKfUboVhKpWi3b WQdWEQFanNvt30krx7BGnJ76Jq/kVa2FK40D6pZ93SRP42RoZ9LJhnFwi0MBQhs3ev54 ycQNRTiQbLkhvFb4nUp/wAS6t2ui3TbkRXXjxtBqq/pi/ow34ShWIlPP/7zwVD9Cs1Px hPDayJokIL/fMFAKvUCu4d3qG/p+QXj0kYADNm3QlUKmNyzOsaxk/3zJpInw9LxPtpTz EuWm6QU0jNpCtvs/9SXpGIM43rtuh511BKbzNMmNfM0SfR1aAiMgx5QserN2lWowCpIw SJNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=xN7KEYZ9pR7gVi6zMi8zHdassp7hlEpZ4bgzEC5iNSM=; b=AvnOyOcM5LurAHhaRm4x/soJ11uuJyNx/9z8VY8m5E79UTGEMAoQuV5rlomlbOS4Md 5koJio7DRfNt8FCTQTFLGwP3hLjkJHaGtCUCwsIf1Iq1n0jg/281Rr7V57lUv48nkhxf nt+mBRhxLiZ741t0AkIAtM3NdwJ2YHH2hfJjP9VAYM2yJQhKtAcG0MS5RcMkN5VXMbbO 9ft+UCZqkV5Eato3qjU891NuD6b4yLTH7hDy/HmONo+xqu309StbARj2Ck39DKJ+8pUe eRIL3/jCGK5tyCwds1JGU/SdoE6aSluHSz0VTYHbAT51wvqItYf/DsglEvKSKpr1ajos dxVg== X-Gm-Message-State: AOAM533OihazR1/ywlKZgQPr+NhYyCuhX5H1UeP9cjVb69/ZCOOjcoJ3 U3wUACQDbNZDXaRampTKbxY= X-Google-Smtp-Source: ABdhPJx8WT74WUiIhq3aCw/S7IQXfBAbEVnqK3qJ/M122pUIeNRqoLCbQcz0TIkpnYVL4dYWK3tylg== X-Received: by 2002:a17:902:cec3:b029:105:fff1:74ad with SMTP id d3-20020a170902cec3b0290105fff174admr5119133plg.69.1623248228607; Wed, 09 Jun 2021 07:17:08 -0700 (PDT) Received: from shinobu ([156.146.35.76]) by smtp.gmail.com with ESMTPSA id s3sm27445pgs.62.2021.06.09.07.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Jun 2021 07:17:07 -0700 (PDT) Date: Wed, 9 Jun 2021 23:16:50 +0900 From: William Breathitt Gray To: Dan Carpenter Cc: jic23@kernel.org, linux-stm32@st-md-mailman.stormreply.com, kernel@pengutronix.de, a.fatoum@pengutronix.de, kamel.bouhara@bootlin.com, gwendal@chromium.org, alexandre.belloni@bootlin.com, david@lechnology.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, syednwaris@gmail.com, patrick.havelange@essensium.com, fabrice.gasnier@st.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, o.rempel@pengutronix.de, jarkko.nikula@linux.intel.com Subject: Re: [PATCH v11 26/33] counter: Add character device interface Message-ID: References: <2b9526ab7f2de91bb867cbd3b12552c77c00b655.1623201082.git.vilhelm.gray@gmail.com> <20210609080708.GL10983@kadam> <20210609085938.GM10983@kadam> MIME-Version: 1.0 In-Reply-To: <20210609085938.GM10983@kadam> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210609_071709_831136_BCED545A X-CRM114-Status: GOOD ( 23.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============4605901844587930474==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============4605901844587930474== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6W+PPeNZqxPVxyi9" Content-Disposition: inline --6W+PPeNZqxPVxyi9 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 09, 2021 at 11:59:38AM +0300, Dan Carpenter wrote: > On Wed, Jun 09, 2021 at 05:28:10PM +0900, William Breathitt Gray wrote: > > On Wed, Jun 09, 2021 at 11:07:08AM +0300, Dan Carpenter wrote: > > > On Wed, Jun 09, 2021 at 10:31:29AM +0900, William Breathitt Gray wrot= e: > > > > +static int counter_set_event_node(struct counter_device *const cou= nter, > > > > + struct counter_watch *const watch, > > > > + const struct counter_comp_node *const cfg) > > > > +{ > > > > + struct counter_event_node *event_node; > > > > + struct counter_comp_node *comp_node; > > > > + > > >=20 > > > The caller should be holding the counter->events_list_lock lock but i= t's > > > not. > >=20 > > Hi Dan, > >=20 > > The counter_set_event_node() function doesn't access or modify > > counter->events_list (it works on counter->next_events_list) so holding > > the counter->events_list_lock here isn't necessary. > >=20 >=20 > There needs to be some sort of locking or this function can race with > itself. (Two threads add the same event at exactly the same time). It > looks like it can also race with counter_disable_events() leading to a > use after free. All right, I'll add in a lock to protect this function so it doesn't race with itself nor counter_disable_events(). > > > > + /* Search for event in the list */ > > > > + list_for_each_entry(event_node, &counter->next_events_list, l) > > > > + if (event_node->event =3D=3D watch->event && > > > > + event_node->channel =3D=3D watch->channel) > > > > + break; > > > > + > > > > + /* If event is not already in the list */ > > > > + if (&event_node->l =3D=3D &counter->next_events_list) { > > > > + /* Allocate new event node */ > > > > + event_node =3D kmalloc(sizeof(*event_node), GFP_ATOMIC); >=20 > Btw, say we decided that we can add/remove events locklessly, then these > GFP_ATOMICs can be changed to GFP_KERNEL. Because I'll be using a lock I'll keep these as GFP_ATOMICs afterall. Thanks, William Breathitt Gray --6W+PPeNZqxPVxyi9 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIyBAABCgAdFiEEk5I4PDJ2w1cDf/bghvpINdm7VJIFAmDAzUgACgkQhvpINdm7 VJKl3w/4kNd0eZ8gex7nYAbTKtDPuPZJ893YlJy3dyc8ONmPcLc6XqU7w9jBT68s ak/7nQW+V685XxVMy/2MoHiEULP/GvWqAiTUJWomApJpSDWfDE70gjBT/70agL69 PprZ4wAoQoFIsVSRbsub57p8cwvuh0YGDyJUQ6+sAXmpi+zZw/RW9UB+WQnnXiye s+DrdDez9PyLkE3hLC/1BNaD0mpcXulhesK7nu50C+FJ//QOUpIvRZwNaohw6hqQ CWC7YsUdN9PwZHIC0BkwpediVffiVTBIgxK1Yqr3+j3kUyKbmY6iHb9PestK170W Q3gHmTPPt0XPE6RnxYTh/Q7fyKbCyHgfBe+Gc8OSHF9pixs737xEKHZcZPX/Lvcz 4i06nJ0mtPSAXpp/9xGHa/+nd/owez2bO2P22v9d7TXcS58qNLbSdBf4/VNj4d4i W2BKxNY0Xl0MOzMf5vWZ9b0ycW3ns9L4Ld0EvdoEba03MegzROrSwwcvcNZiI4jl v3yE0U+GASUGcUiVPN4TH8Ep187XlJ2/klDXNYLSa9+D4zBaFDtPM+lIgc/ZHU8c DKq9voEpZ84BloICz1QrJo5iLOSDzcKphh9ywYA/6Nshr1aoPy6i1jFHPc0Wby98 2CJ4Qa9sS+cRiRIcII1Ll50ofcdpcdivF1OaSmHEwuTIXKbzOw== =d68x -----END PGP SIGNATURE----- --6W+PPeNZqxPVxyi9-- --===============4605901844587930474== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============4605901844587930474==--