Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7708806rwb; Wed, 23 Nov 2022 09:42:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5MtpuB8oW3b+x/VJ9AjGcEnu66RrIT0XKD52V6RIFF5OOrD/TLvlaJHlX0uKA1tiv9UFlH X-Received: by 2002:aa7:c60b:0:b0:462:750b:bced with SMTP id h11-20020aa7c60b000000b00462750bbcedmr25816936edq.313.1669225339000; Wed, 23 Nov 2022 09:42:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669225338; cv=none; d=google.com; s=arc-20160816; b=B2cOYUO09l2aJ17p3TTGsyHqyclTjZD1L4r+vmKGAJDhsJZtuoajK12G8NRLDTDSIb vgLwrUaxyEdEVOIWx7z3udQLT3Zjl4aRTzm26kCzLYxyt/Eznnm6poW/DxUI9KdBZNBo gakIAdk1PE4u6cnN9nEH4ROvV5KOk2TUQrmuHsr3pHnpNz6Q4NeipmzlL3YAOSh3eSot 8udrnjHHXLVMKgkgrCBrZEG45M8DNFH3+HUYada3nktEK9bYH0bEHuICVvohmNk5ALtn Cr1I3auKG5NF8P7w5OHAaecZ5Ai0X47xv1wKO0q8OLLoghDLf1i3Gv7D4ACp5uKV14K6 o1Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6abR5j0hlMc008eliuHFOuiB/x1h/HoL7zgQ4kEGBMg=; b=Q56Wz7DfY33RniDvHAYfsnO7Y+A404vWw02v5d/835uyptF23jjxeuTw7TpQ7W5xdI z2ogD+NbyWCsMZyp3pfjqd/Gz0WYVRApOiylw3dCdiTXvDiF8EZPYBiTWqWCgOo6byJV Wiv/Rck1QhdPm03DFX1EnijkEtEQQjfVwEuBr2oELBpkthZRy2mtTnnoDZ/ktVHWkyKH QTF2il21iBV7YtmLkQ2113+b6gt9Fs+CBREh0wVxTBaZHDusHue3w0ORHY2pEdW0+pyr hGt63G1SFoFTxXJuX+WYYtei5V3fpqbimnt5lA04BlhnmZku2C8CVSkLsFfYZr425BES n6fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=QdimsGNf; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x10-20020a1709060a4a00b0078223ff2756si11157705ejf.244.2022.11.23.09.41.53; Wed, 23 Nov 2022 09:42:18 -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=@ziepe.ca header.s=google header.b=QdimsGNf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237899AbiKWRaZ (ORCPT + 89 others); Wed, 23 Nov 2022 12:30:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239061AbiKWRaA (ORCPT ); Wed, 23 Nov 2022 12:30:00 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5B878E084 for ; Wed, 23 Nov 2022 09:29:58 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id s4so11671320qtx.6 for ; Wed, 23 Nov 2022 09:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=6abR5j0hlMc008eliuHFOuiB/x1h/HoL7zgQ4kEGBMg=; b=QdimsGNfTzv5cy4RlQtfTKKDVSVgL8yuEuK366wzZaMiRqxQeXrAmjllaGNMyScpdc MsNj5mbl3pLDNd2BV325hkTwPL9BYOzi+kSwJtllQ0DULWANmidzNeIUXiQk3VoNfo/E 4ptv6rfZ5hd4J7x9tjAwSNGafLibrKF4EVw5LGSe1ZZy6+s8bRLN4jhguOSkiDMu6QPi wPTI6VMOMjq510vQvLMtGptkpvLXdJgY7O2FNJzlSZh8JHnJa/Z4WKXEodaMMk2QwC7K RiiKOKWHUqu9/c7mJwob6VF0WfIK7heBoUcwO8au92H5yk7bWPYSDK9PEgWhaqz377vC k3ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6abR5j0hlMc008eliuHFOuiB/x1h/HoL7zgQ4kEGBMg=; b=2FoS8boYBA6LjKsbI4AtfD5d5XPLeutkvGGEViEXh6GwTalYy1oAqNN4HC2E4ivVj0 2IMDOrjRR0dxrGIVdU1hDQC0QH8fi1LnAhCB6ktaps01EKTtzLqTajVP4bkaSrWH9oN/ TP577JIsOHMaAx/7dBRoT+DtuGjm2a46TkM2spIAyDiXNt7t/s6Ng79lZYWwInrX+2/g +f7yu0iYOzdttz67P1vn5cBAt3r8N6Wx3DiVarPmHV1Pvnmm0zOd/WBQslOuosZI3YWH YvCTins48AxW9wm7Mylv+nSiLIQpdYCcULbBmw55nroBL2epkyYHkulUpFm/OVwBkBuj CE4g== X-Gm-Message-State: ANoB5pnGTSAXvRrPhebfiR7XIRscGOGlr3HFQ3cWhnlHT/Fwe2Qjs3Ff HXV2/UbuF+xqKlsDkBrL6M9s8A== X-Received: by 2002:a05:622a:5819:b0:3a5:5d34:66a9 with SMTP id fg25-20020a05622a581900b003a55d3466a9mr11256824qtb.623.1669224598066; Wed, 23 Nov 2022 09:29:58 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-47-55-122-23.dhcp-dynamic.fibreop.ns.bellaliant.net. [47.55.122.23]) by smtp.gmail.com with ESMTPSA id bq30-20020a05620a469e00b006ef1a8f1b81sm12581219qkb.5.2022.11.23.09.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:29:56 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1oxtZM-00ATfh-9i; Wed, 23 Nov 2022 13:29:56 -0400 Date: Wed, 23 Nov 2022 13:29:56 -0400 From: Jason Gunthorpe To: Greg Kroah-Hartman Cc: Matthew Wilcox , Maximilian Luz , Andy Shevchenko , 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 , 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 Subject: Re: [PATCH 3/5] driver core: make struct device_type.uevent() take a const * Message-ID: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 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 Wed, Nov 23, 2022 at 06:01:47PM +0100, Greg Kroah-Hartman wrote: > On Wed, Nov 23, 2022 at 12:25:32PM -0400, Jason Gunthorpe wrote: > > On Wed, Nov 23, 2022 at 04:37:59PM +0100, Greg Kroah-Hartman wrote: > > > static inline struct device *__kobj_to_dev(struct kobject *kobj) > > > { > > > return container_of(kobj, struct device, kobj); > > > } > > > > > > static inline const struct device *__kobj_to_dev_const(const struct kobject *kobj) > > > { > > > return container_of(kobj, const struct device, kobj); > > > } > > > > > > /* > > > * container_of() will happily take a const * and spit back a non-const * as it > > > * is just doing pointer math. But we want to be a bit more careful in the > > > * driver code, so manually force any const * of a kobject to also be a const * > > > * to a device. > > > */ > > > #define kobj_to_dev(kobj) \ > > > _Generic((kobj), \ > > > const struct kobject *: __kobj_to_dev_const, \ > > > struct kobject *: __kobj_to_dev)(kobj) > > > > > > > > > Want me to do the same thing here as well? > > > > It would be nice to have a shared macro code gen all of the above > > instead of copy and pasting it. Then maybe other cases beyond struct > > device could adopt const too.. > > I think I tried to create such a beast, but failed, so ended up > open-coding it in a few places in the USB headers already. I can try it > again, but the redirection gets tricky (defines creating defines...) This seems OK: #define generic_container_of(in_type, in, out_type, out_member) \ _Generic(in, \ const in_type *: ((const out_type *)container_of(in, out_type, out_member)), \ in_type *: ((out_type *)container_of(in, out_type, out_member)) \ ) #define kobj_to_dev(__kobj) \ generic_container_of(struct kobject, __kobj, struct device, kobj) Jason