Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3334064pxb; Sat, 9 Oct 2021 07:48:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzndz8rHUQtwhvuTs+gXHrP0hDieZcXX+tRjAWTLX5epoOtugKVhjqWtdeWEgpsu00T9WrT X-Received: by 2002:a17:90a:1f05:: with SMTP id u5mr18586030pja.193.1633790896188; Sat, 09 Oct 2021 07:48:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633790896; cv=none; d=google.com; s=arc-20160816; b=sj0N5SZukEKpAVDo2FWlQsrVI89iSSywJN64QI12pt7cWyNO6vAmIHt9O7Rt54PLrt OgbrJG9UWkuohkM85je4SUqu1IT7FRVJg2ldC7D/D80TTVrv86KPCyMsFKd0W7h6nxcK rXCwKEccTF89RY5c94prHZerrRBd6yMGZ/pO/oszzUTi5KFsvIIzxhdGxQZB9ax7Or/9 uISgwE6AP4aTDm3ZpXYoIQdZBJYXyDBHd5ty6jIuUcpx/jZUG8ENf/NoAMpSVnovedez AfaqUjBMCi6JxsPJiahghnBZH4QwMydWCoD8l56GghnhrDa6Dq2a8WP8EgMbvM0pEDh4 rEwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=C+x39jmHq8RQg6vmuJTMtrdvhN5piCFzTvf7qxI80EA=; b=um+VyklC90N/aol94SbJrZak2gmq5emSPncHCPi8fAuUusItUFtURnqgU5WrJ4KlEA GNiQo5GaAYJtnixfqnRmoAibzbaeaBXm2DvkKobRV0Nfr0a59cP3dKWr415/1VGhI5JF LfCSklBLozdg1R9QKkQpB7meJF2Ao6JJCAozqsfhgoymXtGfe04hsozVx+kXbNDrnvcm Mchx8dcLQM8U1QviSZNBDqfamkyPbNYqRgXBX+CL5q88QB4R8jrLLdI4Fu8S4r3+S7xf K0eWZ3MveGMeK20oAir97BWEwb9kXz8SP0YNMuEJCLn4nVv3PIrb+xsB1bYuHITUsrTw iHTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si4108478plx.101.2021.10.09.07.48.03; Sat, 09 Oct 2021 07:48:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234136AbhJIOtB (ORCPT + 99 others); Sat, 9 Oct 2021 10:49:01 -0400 Received: from mail-oi1-f177.google.com ([209.85.167.177]:41690 "EHLO mail-oi1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233789AbhJIOtA (ORCPT ); Sat, 9 Oct 2021 10:49:00 -0400 Received: by mail-oi1-f177.google.com with SMTP id s24so17721987oij.8; Sat, 09 Oct 2021 07:47:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=C+x39jmHq8RQg6vmuJTMtrdvhN5piCFzTvf7qxI80EA=; b=1zdkZhPeF1FmegjE/1uTBKwwMuZFsGu8KCCpjJZwPGsJ+MEkIvOr3po1xwXuqZKkTX Fs8JcDfNAbzEs3iUQtlOuEdmSDK6BnVBRbYoxDt4pX+jm78oveAIIZshrIePlXR6V3qu BD3lDLh2sX8fGcfsrCdDf0r+2PO7W+QtLaH1Ad5hdOSAZwblY5vsbzb9mkaqEq0XdnCu O5RcUMg7UGVLlvahB+sG+den39yEJpR4hF2zABUQjnonNd8h/0g51qbmx2riEFshHr5r AJDIWq6cJby4v6wZPzhdnl5E4OwOtHhYJ5WGGH4F7KyRbnB72MQ9cwvaFmxpmdVMSJYS CkAw== X-Gm-Message-State: AOAM533nBqJfP0KnfYKeWNyTYVOyr1R650bz9PZZyebB6VvmSRjj4b64 m+qJuCqdKvsZ6jkyy8mLRR6mkEy+p0I1wGrn7CI= X-Received: by 2002:aca:5c5:: with SMTP id 188mr5863261oif.154.1633790823222; Sat, 09 Oct 2021 07:47:03 -0700 (PDT) MIME-Version: 1.0 References: <20210917072732.611140-1-abailon@baylibre.com> <20210917072732.611140-3-abailon@baylibre.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Sat, 9 Oct 2021 16:46:52 +0200 Message-ID: Subject: Re: [PATCH v2 2/2] thermal: add a virtual sensor to aggregate temperatures To: Alexandre Bailon Cc: "Zhang, Rui" , Daniel Lezcano , Amit Kucheria , Linux PM , Linux Kernel Mailing List , ben.tseng@mediatek.com, Kevin Hilman , Matthias Kaehlcke , kernel test robot Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 7, 2021 at 6:38 PM Rafael J. Wysocki wrote: [cut] > > +static int virtual_thermal_sensor_probe(struct platform_device *pdev) > > +{ > > + struct virtual_thermal_sensor *sensor; > > + struct device *dev = &pdev->dev; > > + struct of_phandle_args args; > > + u32 type; > > + int ret; > > + int i; > > + > > + sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); > > + if (!sensor) > > + return -ENOMEM; > > + > > + sensor->count = of_count_phandle_with_args(dev->of_node, > > + "thermal-sensors", > > + "#thermal-sensor-cells"); > > + if (sensor->count <= 0) > > + return -EINVAL; > > + > > + sensor->sensors = devm_kmalloc_array(dev, sensor->count, > > + sizeof(*sensor->sensors), > > + GFP_KERNEL); > > + if (!sensor->sensors) > > + return -ENOMEM; > > + > > + for (i = 0; i < sensor->count; i++) { > > + ret = of_parse_phandle_with_args(dev->of_node, > > + "thermal-sensors", > > + "#thermal-sensor-cells", > > + i, > > + &args); > > + if (ret) > > + return ret; > > + > > + ret = virtual_sensor_add_sensor(sensor, args, i); > > + if (ret) > > + return ret; One more issue that escaped me earlier is that if the hardware sensor being looked for is not there in the thermal_sensors list at this point (say because it has not been added to it yet by whoever is expected to do that), the above will return -ENODEV and all probe will fail without a way to retry. It would be better to return -EPROBE_DEFER from here IIUC. However, this still wouldn't address a more general issue that if the hardware sensor gets unregistered and then registered again (eg. by unloading and reloading a module managing it), it will not be added back to the corresponding virtual sensor's data set. This should not be very hard to address and it would take care of the above initialization ordering issue automatically.