From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02687C4332F for ; Wed, 23 Nov 2022 18:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238683AbiKWS0G (ORCPT ); Wed, 23 Nov 2022 13:26:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236748AbiKWS0G (ORCPT ); Wed, 23 Nov 2022 13:26:06 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71B3E657F1 for ; Wed, 23 Nov 2022 10:26:01 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id jr19so11784756qtb.7 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=SZnUDnmnbTpbDdK4esmI2rT8711ed/ShG1WYz91xl+NsZgmsKtzMsFTaZxq7RK6Zvk qrT1BfHgw93TpGkvcPERfOt08tFoHyNNRcyawcWL5v9XrwQKxItwrSwybOU1n7KMjihY tFjsI+KCn2InXmy60mu3t89uKZUy0gPyxDZL6J/+5URsrExV9Qz1DoDrCGo5VA1HzZ9u h2eMUe2BzFZ7fnF3++qOw/i2uho7k5tr+nlLu++aEXK5XPjbg9w8FBKeIrFi6z7YPIyh MIaZGtXjnkHqkEChEmTVxFhR1D0IV4djz37iP9WDd+wiZl5HPfwc3oG51nS+Ae92RgdJ i0jg== X-Gm-Message-State: ANoB5pnBXnjRWBJe1S4Ki8zpEVsk24OFZM+IQEUe+CcgvLz34jc1PGp/ XJK8uIhxzZg4L+5PNJvkb22VSQ== X-Google-Smtp-Source: AA0mqf7b8dECsNl10eMwxdSE/ntYRY0ZHq3jcx6smQ+WjEjXUXHAE2sWPKfXnqS1wuH6GWMgna/H+Q== 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: Precedence: bulk List-ID: X-Mailing-List: linux-acpi@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