Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7536426rwb; Wed, 23 Nov 2022 07:41:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4YKmyLH8bV+QsDccKmVp9TIYnqevECxwfoJku3SmbmfFHri76BPrF/8/Y4DfiO5+kZ7Qi9 X-Received: by 2002:a63:ec07:0:b0:470:90f1:6216 with SMTP id j7-20020a63ec07000000b0047090f16216mr26545608pgh.42.1669218065307; Wed, 23 Nov 2022 07:41:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669218065; cv=none; d=google.com; s=arc-20160816; b=cNJ73E2xQmVA4v/4ORUXd+5mbetwL+6zxsKMAQVn1ZsfVNtZc9UrbYOhWDfcx0yQRe tRkWR2R9jxoJ3mnR0LkpYMqI5ydlm5VsE4zgJgfm2H0mxhus+CHvTe66eAgEP/w4tfOE 1G7Q5duIxUF4EYETdUxXuIyICwrwmbDDW3p7iEy8KzG7gUsSXXe0U0uBcOlIB5r38rEo xRgoFYVST09PUU99tDfPtiqZHuM/5Zp0qA7aQ3kGHFJR4cfcGLS4YVvklBbCk3nSlLgw N8o2HthFh1EFRHTIm2y6+Uqisjla6/lT0bC6+3irEeB4NoGPVOIC8/j1dQMv42gEqHXQ z4AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=hgnV7dzGWIIK4HLAnWBaJEBL2mTLW/I0cvrJZ3aQwLQ=; b=amSFM3H64bRFPbINVLvG+CfTJqErQ219nVwdhf0aADWpETM4hSQNVi8kQM6WvJgKBX WSwhPZJhNwoCInyHfVd9HC6c0bFwjXtOidQR4FHou6msveK1gfgfF3WMxnu3Mg546ZRg IOQYhxmboDAE8qlUvJrcDDXjLdqodwHY64somVEU+nUz81STg3R4aH2A48EVC0nib3yd dHBo5hVh4JrqZSBfIW4aoFR6P1G5wFkAFczf2+NZUeOxJ13ngwkjwpPuggH0Vu+MJJ8O iQ09O+3KJ5hw5IT17lCMOxasdH4jZQ25EADzkSUvfSfU1/+gqAKpdEd2y3EOcWH/PsIA 27jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="YMJ/LWVH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a170903244c00b00186ada5d4e2si1039736pls.215.2022.11.23.07.40.53; Wed, 23 Nov 2022 07:41:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="YMJ/LWVH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238490AbiKWPO3 (ORCPT + 88 others); Wed, 23 Nov 2022 10:14:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238316AbiKWPO1 (ORCPT ); Wed, 23 Nov 2022 10:14:27 -0500 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4670685EC9; Wed, 23 Nov 2022 07:14:26 -0800 (PST) Received: by mail-ej1-x62b.google.com with SMTP id m22so43412713eji.10; Wed, 23 Nov 2022 07:14:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=hgnV7dzGWIIK4HLAnWBaJEBL2mTLW/I0cvrJZ3aQwLQ=; b=YMJ/LWVHtvivchBTzQwnK1vjlMO+Yz1qi3F+5UiPUgfXYsHW97FLmplkkb1fg1J6+K goYB9EqDRSGMEVxvnaAeVTF9Lc9Gf4uLBWSxTIzEd4dGukliptoZ4n3exYdegKJZSLxS jqqRYMpOfvNhGznAoadCbX01da13AhoRzrTcCdNaWrn84IMP2tAXwxgcb2DgicvEWWfp i43A/VFojKzoOpulaS8VMliUQvFXuOXde7c6MUNzuEGgGRk68D/p2retyzW7n9p5jNzk Eo7b36EnX4jR3LhMZcShGFxfcBKk4/LQlmgUCRROq02DkIDupJ6I37wpVS8vwAn/gosV VeGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=hgnV7dzGWIIK4HLAnWBaJEBL2mTLW/I0cvrJZ3aQwLQ=; b=LzuxTEdqA88PnYU4gqT00hsmfe67JhBfKZ8N7IREaY72Vtlxa1J4d2A5b4VmXQhz9z mXz+qWJYkUortzDNKIXvMyqn7zEnb5Sb6uxwfj/eUYH8tN16wgfvdpozZN0nsNmr/SCh rLC5YlCQfeGBdZrpVYRvDDG0dspymCOOKVoCex03xPm5YmNbC1ZWu4BuPPED6XTpFiKf LdTF54y88fC+9vSY/Y76BCyWRc/o6ivE4ARSbGre2tXEvoUStPa/ZHlQhpbOhaYXgKpz 6YMKX5OR63pfLb7p+9vhHL940BZTMi0zW14BmRwDnTV2ZBtG5QAwDOsnqQ5CXeztWul/ 49DQ== X-Gm-Message-State: ANoB5plzpdHvWBZeaU8nqPhHKmuMaKrgMbNlahjL3mNV2KIcYlMcVpPm LQhYbY1+OgPD3rtZ02FBKrk= X-Received: by 2002:a17:906:402:b0:7a6:fc0f:6fe6 with SMTP id d2-20020a170906040200b007a6fc0f6fe6mr23229240eja.694.1669216464581; Wed, 23 Nov 2022 07:14:24 -0800 (PST) Received: from [10.20.0.7] ([37.120.217.162]) by smtp.gmail.com with ESMTPSA id ky13-20020a170907778d00b0077a1dd3e7b7sm7251748ejc.102.2022.11.23.07.14.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Nov 2022 07:14:23 -0800 (PST) Message-ID: Date: Wed, 23 Nov 2022 16:14:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH 3/5] driver core: make struct device_type.uevent() take a const * Content-Language: en-US To: Matthew Wilcox Cc: Andy Shevchenko , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, Jens Axboe , "Rafael J. Wysocki" , Len Brown , Stefan Richter , Wolfram Sang , Alexandre Belloni , Dmitry Torokhov , Sean Young , Mauro Carvalho Chehab , Rob Herring , Frank Rowand , Hans de Goede , Mark Gross , Vinod Koul , Bard Liao , Pierre-Louis Bossart , Sanyog Kale , Andreas Noever , Michael Jamet , Mika Westerberg , Yehezkel Bernat , Jiri Slaby , Heikki Krogerus , "Martin K. Petersen" , Chaitanya Kulkarni , Ming Lei , Jilin Yuan , Alan Stern , Sakari Ailus , Jason Gunthorpe , Thomas Gleixner , Ira Weiny , Dan Williams , Won Chung , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-block@vger.kernel.org, linux-i2c@vger.kernel.org, linux-i3c@lists.infradead.org, linux-input@vger.kernel.org, linux-media@vger.kernel.org, linux-serial@vger.kernel.org, linux-usb@vger.kernel.org, linux1394-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org References: <20221123122523.1332370-1-gregkh@linuxfoundation.org> <20221123122523.1332370-3-gregkh@linuxfoundation.org> <711d5275-7e80-c00d-0cdc-0f3d52175361@gmail.com> <97be39ed-3cea-d55a-caa6-c2652baef399@gmail.com> From: Maximilian Luz In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/23/22 15:52, Matthew Wilcox wrote: > On Wed, Nov 23, 2022 at 02:59:00PM +0100, Maximilian Luz wrote: >> On 11/23/22 14:34, Andy Shevchenko wrote: >>> On Wed, Nov 23, 2022 at 02:14:31PM +0100, Maximilian Luz wrote: >>>> On 11/23/22 13:25, Greg Kroah-Hartman wrote: >>>>> The uevent() callback in struct device_type should not be modifying the >>>>> device that is passed into it, so mark it as a const * and propagate the >>>>> function signature changes out into all relevant subsystems that use >>>>> this callback. >>> >>> [...] >>> >>>>> -static inline struct ssam_device *to_ssam_device(struct device *d) >>>>> +static inline struct ssam_device *to_ssam_device(const struct device *d) >>>>> { >>>>> return container_of(d, struct ssam_device, dev); >>>>> } >>>> >>>> I am slightly conflicted about this change as that now more or less >>>> implicitly drops the const. So I'm wondering if it wouldn't be better to >>>> either create a function specifically for const pointers or to just >>>> open-code it in the instance above. >>>> >>>> I guess we could also convert this to a macro. Then at least there >>>> wouldn't be an explicit and potentially misleading const-conversion >>>> indicated in the function signature. >>> >>> This is an intermediate step as far as I know since moving container_of to >>> recognize const is a bit noisy right now. I guess you can find a discussion >>> on the topic between Greg and Sakari. >> >> Thanks! I assume you are referring to the following? >> >> https://lore.kernel.org/lkml/4218173bd72b4f1899d4c41a8e251f0d@AcuMS.aculab.com/T/ >> >> As far as I can tell this is only a warning in documentation, not >> compile time (which would probably be impossible?). >> >> As I've said I'd be fine with converting the function to a macro (and >> preferably adding a similar warning like the one proposed in that >> thread). The point that irks me up is just that, as proposed, the >> function signature would now advertise a conversion that should never be >> happening. >> >> Having two separate functions would create a compile-time guarantee, so >> I'd prefer that, but I can understand if that might be considered too >> noisy in code. Or if there is a push to make container_of() emit a >> compile-time warning I'd also be perfectly happy with converting it to a >> macro now as that'd alleviate the need for functions in the future. > > Can't we do: > > static inline const struct ssam_device *to_ssam_device(const struct device *d) > { > return container_of(d, const struct ssam_device, dev); > } There are at least a couple of places (device/driver-management and device-removal related, I think) using this function and requiring non-const access. A bunch of other instances could be converted to const-access only, but that would require a couple more function signature changes (I should probably set up a patch for that regardless of this here as being a bit more strict about this makes sense). Regards, Max