From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726415AbgIIL2a (ORCPT ); Wed, 9 Sep 2020 07:28:30 -0400 From: Michael Ellerman Subject: Re: [PATCH v2 3/7] mm/memory_hotplug: prepare passing flags to add_memory() and friends In-Reply-To: <3bc5b464-3229-d442-714a-ec33b5728ac6@redhat.com> References: <20200908201012.44168-1-david@redhat.com> <20200908201012.44168-4-david@redhat.com> <20200909071759.GD435421@kroah.com> <3bc5b464-3229-d442-714a-ec33b5728ac6@redhat.com> Date: Wed, 09 Sep 2020 21:24:02 +1000 Message-ID: <87eenbry5p.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-s390-owner@vger.kernel.org List-ID: To: David Hildenbrand , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, linux-hyperv@vger.kernel.org, xen-devel@lists.xenproject.org, linux-acpi@vger.kernel.org, linux-nvdimm@lists.01.org, linux-s390@vger.kernel.org, Andrew Morton , Wei Liu , Michal Hocko , Dan Williams , Jason Gunthorpe , Pankaj Gupta , Baoquan He , Wei Yang , Benjamin Herrenschmidt , Paul Mackerras , "Rafael J. Wysocki" , Len Brown , Vishal Verma , Dave Jiang , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "Michael S. Tsirkin" , Jason Wang , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Oliver O'Halloran , Pingfan Liu , Nathan Lynch , Libor Pechacek , Anton Blanchard , Leonardo Bras , linuxppc-dev@lists.ozlabs.org David Hildenbrand writes: > On 09.09.20 09:17, Greg Kroah-Hartman wrote: >> On Tue, Sep 08, 2020 at 10:10:08PM +0200, David Hildenbrand wrote: >>> We soon want to pass flags, e.g., to mark added System RAM resources. >>> mergeable. Prepare for that. >> >> What are these random "flags", and how do we know what should be passed >> to them? >> >> Why not make this an enumerated type so that we know it all works >> properly, like the GPF_* flags are? Passing around a random unsigned >> long feels very odd/broken... > > Agreed, an enum (mhp_flags) seems to give a better hint what can > actually be passed. Thanks! You probably know this but ... Just using a C enum doesn't get you any type safety. You can get some checking via sparse by using __bitwise, which is what gfp_t does. You don't actually have to use an enum for that, it works with #defines also. Or you can wrap the flag in a struct, the way atomic_t does, and then the compiler will prevent passing plain integers in place of your custom type. cheers