Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4141535rdb; Mon, 11 Dec 2023 09:58:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcdNkR2Wxb3+7dlR/Whi/NF1pu800duJvWSDqfwDcrfv6eXIYbMNHS+Q9EsicmMD8SGhnz X-Received: by 2002:a17:903:298e:b0:1d0:d196:2658 with SMTP id lm14-20020a170903298e00b001d0d1962658mr3027963plb.19.1702317503464; Mon, 11 Dec 2023 09:58:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317503; cv=none; d=google.com; s=arc-20160816; b=hhkrAg4ln3pJquR50cpmP8YcladzG1NHFbKGNYtPqROOo15e+UlqsYPXrRfA3dCWOQ ShM8bAtaHQ4KuPQ/I79x7/EX+yovt3O/UBj9iHuKARjrJ4+xzaE9oyIghFRFfuNJEkuo pE/+tMXc0HGmnDRnZ+3HxLoFvvRFvv1ZFAZ7/Oy4nwvaZzYFzDOHeBpWBmMDGl6WpwF4 pEjeCHtr7mf85Y2xOU6BhdSKbOHFs4KIfBp6qrUqy1nWpXRrG6eQPxn2jMz/KoD9f/UL 0pM4U7GGgbpXaCsfLZe6mGw5Rn4C32ZJcmsORn5u4yPO/9wR7cP+4aZE3RTb3rTmQvD/ sKCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=oqPI77t0DoClRh+ntoumnt9D3g8ONRgz75Ue8CRqHIc=; fh=uDfSeyQcicFPe9yKG3eLk/KL9G6+nqtKqMbn80XCcZM=; b=beWE/mOnyTQ/N10OcQRjQ5b2JdGNSUPiqS7j1uXtuvAboqyK+qUqz+6taMOQJOkMy2 EHiqIToVRM/Er9RrtOyVjJVxRF9OI9WarjGSgQabZOGwBqwPOW42JHFt8O9sjVwTcTui d4qvkkTxr31m5G+gWEfgprUTHqTRmZ3nxj1kcfhy6+2L3R9lA61Qalzup4J52T78AQu4 XspolkjH9ZISmJce1sy2fICUOUqWdWiyTGJBLrkUWnpwy9N+7X6RxgkbkPldJozKa4tQ Ekh92OCMvBkLZ5qT8I1HlXzpc/K1rRCNk/VEjIS2jQKZ4LdETDwvxGPunW+e3wVcK8le T+GQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id je1-20020a170903264100b001d06e8a15desi6330486plb.322.2023.12.11.09.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:58:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D48B4809AFCD; Mon, 11 Dec 2023 09:58:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345095AbjLKR6H convert rfc822-to-8bit (ORCPT + 99 others); Mon, 11 Dec 2023 12:58:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344957AbjLKR6G (ORCPT ); Mon, 11 Dec 2023 12:58:06 -0500 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB5193; Mon, 11 Dec 2023 09:58:12 -0800 (PST) Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6d9db92bd71so600219a34.1; Mon, 11 Dec 2023 09:58:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317491; x=1702922291; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OXbiTpVzJfHRl7QZFMGmf1sW13oDT9FBF5f3B7KPSvc=; b=AZLuqQHAZbxrleryKoiCa7ycnnmw1g7zBi3m56KgedN562h66X4iIHoeDHcreTH3L7 naAPTlkORp5uZxqi3KijuaFI1dJbRokHtO70Rom/mxKxEyJUgrZSxcejxdkvPbFDfeC/ uz78wbaPSfHc+vWdFt1ZMlHyT/eOX6aIhN3lxPeTHNBImwxclVlcyT+eL5NfHTsl2+pM Ky8KUIHhkPwsoS0wOi98seZFvjSSs/hAkb1I9Rwwgf5EKMUmRGbn6ICITAtZdRsIzsAH p3Dikz61fe51hM8p2RSBkKmpzeZt7R23po+EPt/biQXQpP5fsY04xkLkKXssXdxmJ+7C tFLA== X-Gm-Message-State: AOJu0YzZLDV5C6xY0Y7FwDaYknR0tqSxHkxWjFKi9Q6Qok9pNTnnkvDY fRK5sO4z9OM2gqNRNHeDUamcI27p6wynd3wRBlE= X-Received: by 2002:a05:6871:2284:b0:1fb:648:5207 with SMTP id sd4-20020a056871228400b001fb06485207mr9545202oab.2.1702317491331; Mon, 11 Dec 2023 09:58:11 -0800 (PST) MIME-Version: 1.0 References: <1880915.tdWV9SEqCh@kreacher> <8315317.T7Z3S40VBb@kreacher> <03944e4e-d57d-4442-b38d-e36e20cb5ae3@linaro.org> In-Reply-To: <03944e4e-d57d-4442-b38d-e36e20cb5ae3@linaro.org> From: "Rafael J. Wysocki" Date: Mon, 11 Dec 2023 18:58:00 +0100 Message-ID: Subject: Re: [PATCH v1 2/3] thermal: Drop redundant and confusing device_is_registered() checks To: Daniel Lezcano Cc: "Rafael J. Wysocki" , Linux PM , Srinivas Pandruvada , Zhang Rui , Linux ACPI , LKML , Lukasz Luba Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:58:21 -0800 (PST) On Mon, Dec 11, 2023 at 6:39 PM Daniel Lezcano wrote: > > On 08/12/2023 20:19, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > Multiple places in the thermal subsystem (most importantly, sysfs > > attribute callback functions) check if the given thermal zone device is > > still registered in order to return early in case the device_del() in > > thermal_zone_device_unregister() has run already. > > > > However, after thermal_zone_device_unregister() has been made wait for > > all of the zone-related activity to complete before returning, it is > > not necessary to do that any more, because all of the code holding a > > reference to the thermal zone device object will be waited for even if > > it does not do anything special to enforce this. > > > > Accordingly, drop all of the device_is_registered() checks that are now > > redundant and get rid of the zone locking that is not necessary any more > > after dropping them. > > > > Signed-off-by: Rafael J. Wysocki > > --- > > [ ... ] > > > @@ -132,11 +120,6 @@ trip_point_temp_store(struct device *dev > > > > mutex_lock(&tz->lock); > > > > - if (!device_is_registered(dev)) { > > - ret = -ENODEV; > > - goto unlock; > > - } > > - > > trip = &tz->trips[trip_id]; > > > > if (temp != trip->temperature) { > > @@ -162,23 +145,12 @@ trip_point_temp_show(struct device *dev, > > char *buf) > > { > > struct thermal_zone_device *tz = to_thermal_zone(dev); > > - int trip_id, temp; > > + int trip_id; > > > > if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1) > > return -EINVAL; > > > > - mutex_lock(&tz->lock); > > - > > - if (!device_is_registered(dev)) { > > - mutex_unlock(&tz->lock); > > - return -ENODEV; > > - } > > - > > - temp = tz->trips[trip_id].temperature; > > - > > - mutex_unlock(&tz->lock); > > - > > - return sprintf(buf, "%d\n", temp); > > + return sprintf(buf, "%d\n", tz->trips[trip_id].temperature); > > Without the lock, could the trip_temp_store() make the value change > while we read it? The lock doesn't change that, because the write can occur before dropping the lock and the printf() and reading an int is atomic on all architectures supported by Linux.