Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7866049rwb; Wed, 23 Nov 2022 11:51:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf5LFSzuoCkBXTm6AdEUW01Fn1NJHW32WVECkIu62DvAWmQhN9Qs7Mvkagjhd3Q8ZjWn/YjI X-Received: by 2002:a17:90a:a003:b0:214:1a8a:a415 with SMTP id q3-20020a17090aa00300b002141a8aa415mr31680213pjp.197.1669233073986; Wed, 23 Nov 2022 11:51:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669233073; cv=none; d=google.com; s=arc-20160816; b=CZvDFIc2DOUNMdBecs/FrDHiTw+VgFz6iympsaYuAfXfr5Z1Ehd0uQVv6juh5xJY9W IsNEUqWUyJcD9ur2+oOeiJxNHgHm/sRqyugHVS1WpXX+3Qz/b7zxudZDoRsJVR1oNDR+ V7YvmiBDr8qMXyRbN5g7VkcfdU1nJ/scjc8KcygKUASNfQvKm6uqJXnh0PKgFDu86tTy t+bxKjX0ZVZZnHA5AHQyCFbFlRoEZpZ2c2+MMMPsugFYIFRsA+KyyNHDWQW36lgAsCUe cH+3t5Di3qfD3mbwni52LfvIF5UZaPrRWfuL1ZFr2Dwh5k5++Ui9Aoixg04pMDlkK/IR GzOg== 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=Wor3YG1VA6P7o8c/O7L7eJMI/pZ9HPWWwXQft3hmCP0=; b=Dha6VSkMs+JAl+lka1LagHSllwUzomQ1zpR35R9ifX55tiA63s6H2cVTqFJIrvB+6L RumFH0Ig1S2Ir2pyVcDNi3MBMXWY62vxJXS2Wu3ayY49gcewxEMLjsUKUwTa9HBhrK22 w+sgeZM+KeqK38j/J5wCOrmK4Wn2Dh2jCgmOrxaRYY+yLp7Bru+J3L6FFH40lOGi3I6O 3d+eQ6Z7bQhc6YT1oVjweETBhSAidwSJxiXbr8xdcJ+4fBq3JgR2TAf/ckWouQU34mv7 vQ2e0kWlhxPQJAA1OR198qeF9vdh7bF9bLD853nf6LHn52LC36UCKWh0KtQmqEEgHiNl XyIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=cedo7ZWS; 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 e16-20020a056a001a9000b00572ee9a0c46si13092706pfv.346.2022.11.23.11.50.56; Wed, 23 Nov 2022 11:51:13 -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=cedo7ZWS; 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 S239236AbiKWS0J (ORCPT + 88 others); Wed, 23 Nov 2022 13:26:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238510AbiKWS0G (ORCPT ); Wed, 23 Nov 2022 13:26:06 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7270365875 for ; Wed, 23 Nov 2022 10:26:01 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id l15so11783208qtv.4 for ; Wed, 23 Nov 2022 10:26:01 -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=Wor3YG1VA6P7o8c/O7L7eJMI/pZ9HPWWwXQft3hmCP0=; b=cedo7ZWSmsuH0XJ4ubpV07F12j6QbWjVQ5/8pLuMpcToghtBSuk56S6MXMX6Qm7WjS 1NChO+moKmrDNMneamIggSvWWzwr/T//kN/Kwcj6tkr42ZlPhD/UrODWK93fqzNGGGwJ iaes3XW9eYna/Bw5lL+n4z8tFP5LtgS2cmv98rZ7AlPx3XDSdaiaMvzcA8+djvnqI1Jm kByuaQkEy2IUN0jEoJWE9aJxjegXkz/nFnBqeS7bAW8o6PzzHwTSega1vNzAX6eGe++Z VrL1e2yxkd6Af/0OPW4nuezYyEJvxr1zGiOqJwebNXGUK6ij0o7CaXNXzEmp7wpIRmex 6uNg== 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=Wor3YG1VA6P7o8c/O7L7eJMI/pZ9HPWWwXQft3hmCP0=; b=r+itJBDuVJjAgtUDwBjXIq/QWYBiIxChqmesY+sX+VTFmAMzxXCYviBlfUmNIpr0R8 RqPxZ6mBmtHI500GxElQ4tDxrALRI3ww/L6bXjyvCVfKD3+FPzT4OG9ijw8NE/7ssAqr utVVxM5fR9jRUj9Z1a4kDA6jB8wLKKGZbDa0dlekt1Nz7kl1wXOTHjizzl/+a3d1cl7W fBa9Zyh1jNMYEtdxiOIS6uoA5MZLqcM+7572BmoY5IUP9Cev6EnvrJ5HzjvzNQZCX4VZ OKnSuQKcXtJWW8RJTqu5bveMr9RwOOMPMKoAIO+VdHXEgkBpkrKseCwCDXBsAI4oyq/T iLaw== X-Gm-Message-State: ANoB5pkt4v9RU0bWyiuVKXYftI883C4LQbc4V8nDDvFEBDoAWgLZ/47/ NEIWPsace6OsxmqyUSjdToxGdA== X-Received: by 2002:a05:622a:1f97:b0:3a6:39c4:dc6 with SMTP id cb23-20020a05622a1f9700b003a639c40dc6mr19492448qtb.515.1669227960618; Wed, 23 Nov 2022 10:26:00 -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 e9-20020ac81309000000b003a56796a764sm10034417qtj.25.2022.11.23.10.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 10:25:59 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1oxuRb-00AgEQ-7R; Wed, 23 Nov 2022 14:25:59 -0400 Date: Wed, 23 Nov 2022 14:25:59 -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: <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=unavailable 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 07:10:49PM +0100, Greg Kroah-Hartman wrote: > On Wed, Nov 23, 2022 at 05:49:36PM +0000, Matthew Wilcox wrote: > > On Wed, Nov 23, 2022 at 01:29:56PM -0400, Jason Gunthorpe wrote: > > > #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)) \ > > > ) > > > > There's a neat trick I found in seqlock.h: > > > > #define generic_container_of(in_t, in, out_t, m) \ > > _Generic(*(in), \ > > const in_t: ((const out_t *)container_of(in, out_t, m)), \ > > in_t: ((out_t *)container_of(in, out_type, m)) \ > > ) > > > > and now it fits in 80 columns ;-) > > Nice trick! Dropping the inline functions is a bit different, let me > see if that still gives a sane error if we pass an incorrect type or > mess with the const * the wrong way. I'll run some tests tomorrow > afternoon... The errors in some cases are very verbose, but it is somewhat understandable - the worst is when _Generic fails to match anything, but also at least clang partially expanded container_of and it throws other assertions too. I also wonder if this could just be rolled into the normal container_of. in_type would have to be derived like: in_type = typeof((out_type *)NULL)->out_member) But I don't know if you can use typeof in a generic type matching expression.. Jason