Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp264649rdb; Thu, 22 Feb 2024 03:04:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUy4n46o0rfBaBZ4txIVro/C2yCagsH2/yfqtnR8tAfGqjbF2yUG522DQn0MMYJiV4323L4hrqJ0v+R6rNedJVKm2kFZ0cVzrjsitSgQg== X-Google-Smtp-Source: AGHT+IHiZTXSGUDhuzvTIiFVhqW4kfavusH0OypmZq5pA+0G2A+M4xvma+sKlNSFPN06LMlDIyt1 X-Received: by 2002:a17:90a:68cf:b0:29a:1b37:4c12 with SMTP id q15-20020a17090a68cf00b0029a1b374c12mr3892886pjj.22.1708599864468; Thu, 22 Feb 2024 03:04:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708599864; cv=pass; d=google.com; s=arc-20160816; b=Xb4of77Sd8p4LpGS6qo+291oCEL5peX2aArv6FzdH1bPfKSFFTQh6aZw+3in/CUoeh 3XQl74yXPWL8P5uomU0liI3no8NZxn5xYl3XI2MMKzFJlbXxFpryrxabxUWsWj+HjqOz c7DdJfC2IASCvUIK3ebrv09PcZ5YcpXBawb9KtnKoZFCbHL1FQ0+Hkn2F6/HIHt8kr0a AT2pYxR55NREqcTI++5j3cQHw/Hgkqmakh2iyDfGfOr8gcOwwntppfJE95F5URjwYaIU J7Zrl76nCJPvEbBVS+6HgAce/hYwDGPehz2vPc2Qqx9ysoVCMi32ErExoQLm31BJkvR+ wmMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Jnb5VAlV+t+Y6J33nYp+vDGASZ6SUQSeVwjB1F0eU9Y=; fh=laAkT1F+T4daFvDlJkLNjL+ce8dp08ktlmK55Jmt/DQ=; b=o+NWPbM9uyvfdJurSzGuwlKA95Fqk53TiH8WAAr9OlJ2G9A9FvjwO9X4YM/S7c/tpa S3RVh1jgQ/CySrmH7s6GgDr0+BtUTee5I092gTWGNx57TqhBQT4EyVcugS0ql1QOItgI wV/2j2tvdRFT4VYM9zPGUYb9jprYltI913IO4Y9LmuPoivCj+T51v/g0y/n1jKPp517G s+H4iy4vg/CcWvlTMSoZ/pBuqdOFE74ZmhYIIWhL9DJgnX6CHcwQo2TAKiU60dZ1hYfv T6Yg2NQyqmoVl4PYqYWTr+GbzmeDqKtNPltTlhnoSs2kYeDN12KzpFddg6IgdXucjHln kCtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zqLWrpMc; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-76372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76372-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id pq3-20020a17090b3d8300b0028cb18e31d5si10445312pjb.160.2024.02.22.03.04.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 03:04:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zqLWrpMc; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-76372-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76372-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1A73DB27959 for ; Thu, 22 Feb 2024 10:58:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 880F43FB03; Thu, 22 Feb 2024 10:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zqLWrpMc" Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 561D545945 for ; Thu, 22 Feb 2024 10:58:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708599522; cv=none; b=jXZjHLF5VBFbRe9ZJfTWnxbkmXGFgea5vLpiH/VZDGFqvnh6KIRijs3oj9OEyFgBosZcVKFTyL3V0uSwNharkdDhr/1BwjhrTyVPvNkgtR4nMOf9oCCmG/67TECfBFg1R2orhwxHjeATZ1gQz/+iw2BOaV7yo4nyknwy733t160= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708599522; c=relaxed/simple; bh=MbaHf0aFoYZ+N6o8Nx8FO/BRhrHStIeFx08AcHel/Do=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=urcPLxHE7M33DU98VVvX4kWlmBnzdjr3+QqvY5oj3Roh0y/Av2/xJ95is0aPpwHlpzbX6xxdSlhaC6xeak5s9De7ekZpYp6jP8CldYIetQPiU92GXgWOGJ+jIg2aGAaz1QUX0ps8fbv8OClqQ7wzu9zhVSOhT3uWSeIXhn/WqUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=zqLWrpMc; arc=none smtp.client-ip=209.85.208.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d0e520362cso77747121fa.2 for ; Thu, 22 Feb 2024 02:58:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708599509; x=1709204309; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Jnb5VAlV+t+Y6J33nYp+vDGASZ6SUQSeVwjB1F0eU9Y=; b=zqLWrpMc31DPV52P7E2MWBZx2wG4KfI3J015mydlxCdL43yn7hfpkKKWxV5Ff549cO Iap0yoUPQMELFnbK225/8FxVzrKWst0rsKUrvNFgQ3XsFIRI0fKGZflY7IOqerY5VUpX LWtkg0LOQzI7YsF0N7eRDSQjKpw8FxG8KT9fT64GbYyjtmTQkuOK+rkrvJ3MCY9GpCN2 /sTgVtcYzer2EVvNOxw0RDmlM+W5sovIs6IddtOZzt+sElQM45PBVpCeUtCQfrGfXj3P OCUoRsg+MZcQvvOu7WhUWiUIZlDkPBWX/40XvmDszGiFnQ7UaT49ww+0phweOunvx2t9 D2/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708599509; x=1709204309; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Jnb5VAlV+t+Y6J33nYp+vDGASZ6SUQSeVwjB1F0eU9Y=; b=TWG71Sf7q4YO+w27POpzPCk8jPpn1aLmsvHWAHwwEo+FakV07UFVQBolSKtkci9ulV ntO49x6n2FcxABCtty6ZLTJBBjqPRNSmbBzxknpvcddjsNwZ6rnDifKvIFxdsl5Xyu9l UYlDm9huuO4JKMv6kAuckTCdTOxw1ey7zhvLRvlBkjEIMNOwyrojeK8N3rkmQUWik/zt nrinNq7FHpfZv5g2tXzMWwQE/mzacs0He7SwwDWLH7rs5KTBs3lLbqSfiTTBgRFC2PAJ k1lfvDXUpi+TIFKZRNhNndet21KEJomZv73WUh2smYriwpIRDGfaw4FEyQwuy2dVxP+m YghQ== X-Forwarded-Encrypted: i=1; AJvYcCUOy40rm2IRQRei3JgIJyGtmvEJZE+VpwQB7hRp/7mTj0YG54mFRARMcdoRYj9447eIX9wJksVPlLXC29BHt2/1TQ8nD0dZAq3lLnIR X-Gm-Message-State: AOJu0YyX8mtT4yWtDg1E+n9rprUESLcMGRugdUikKLlYHVJ3JjAw2GGh 1HJ1ZwWh464pIwDX52K7E6nTUZojKYGVtqxhJW64dgeb6ZzfcvWxw/huCHjPHZI= X-Received: by 2002:a2e:a98e:0:b0:2d2:6182:6ca7 with SMTP id x14-20020a2ea98e000000b002d261826ca7mr1203484ljq.39.1708599508674; Thu, 22 Feb 2024 02:58:28 -0800 (PST) Received: from [192.168.10.46] (146725694.box.freepro.com. [130.180.211.218]) by smtp.googlemail.com with ESMTPSA id co18-20020a0560000a1200b0033d4c3b0beesm14836608wrb.19.2024.02.22.02.58.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Feb 2024 02:58:28 -0800 (PST) Message-ID: Date: Thu, 22 Feb 2024 11:58:27 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/6] thermal: core: Store zone ops in struct thermal_zone_device Content-Language: en-US To: "Rafael J. Wysocki" Cc: "Rafael J. Wysocki" , Linux PM , LKML , Linux ACPI , Lukasz Luba , Zhang Rui , Srinivas Pandruvada , Stanislaw Gruszka , AngeloGioacchino Del Regno , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team References: <4551531.LvFx2qVVIh@kreacher> <2262393.iZASKD2KPV@kreacher> From: Daniel Lezcano In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 22/02/2024 11:52, Rafael J. Wysocki wrote: > On Thu, Feb 22, 2024 at 11:47 AM Daniel Lezcano > wrote: >> >> On 14/02/2024 13:45, Rafael J. Wysocki wrote: >>> From: Rafael J. Wysocki >>> >>> The current code requires thermal zone creators to pass pointers to >>> writable ops structures to thermal_zone_device_register_with_trips() >>> which needs to modify the target struct thermal_zone_device_ops object >>> if the "critical" operation in it is NULL. >>> >>> Moreover, the callers of thermal_zone_device_register_with_trips() are >>> required to hold on to the struct thermal_zone_device_ops object passed >>> to it until the given thermal zone is unregistered. >>> >>> Both of these requirements are quite inconvenient, so modify struct >>> thermal_zone_device to contain struct thermal_zone_device_ops as field and >>> make thermal_zone_device_register_with_trips() copy the contents of the >>> struct thermal_zone_device_ops passed to it via a pointer (which can be >>> const now) to that field. >>> >>> Also adjust the code using thermal zone ops accordingly and modify >>> thermal_of_zone_register() to use a local ops variable during >>> thermal zone registration so ops do not need to be freed in >>> thermal_of_zone_unregister() any more. >> >> [ ... ] >> >>> static void thermal_of_zone_unregister(struct thermal_zone_device *tz) >>> { >>> struct thermal_trip *trips = tz->trips; >>> - struct thermal_zone_device_ops *ops = tz->ops; >>> >>> thermal_zone_device_disable(tz); >>> thermal_zone_device_unregister(tz); >>> kfree(trips); >> >> Not related to the current patch but with patch 1/6. Freeing the trip >> points here will lead to a double free given it is already freed from >> thermal_zone_device_unregister() after the changes introduces in patch >> 1, right ? > > No, patch [1/6] doesn't free the caller-supplied ops, just copies them > into the local instance. Attempting to free a static ops would not be > a good idea, for example. I'm referring to the trip points not the ops. The patch 1 does: tz = kzalloc(struct_size(tz, trips, num_trips), GFP_KERNEL); Then the last line of thermal_zone_device_unregister() does: kfree(tz); That includes the trip points in the flexible array. Now in thermal_of_zone_unregister(), we do: trips = tz->trips; thermal_zone_device_unregister(tz); kfree(trips); Hence double kfree, right? > BTW, thanks for all of the reviews, but this series is not applicable > without the one at > > https://lore.kernel.org/linux-pm/6017196.lOV4Wx5bFT@kreacher/ -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog