115dba7a9SFrançois Tigeot /* 215dba7a9SFrançois Tigeot * Copyright (c) 2018 François Tigeot <ftigeot@wolfpond.org> 315dba7a9SFrançois Tigeot * All rights reserved. 415dba7a9SFrançois Tigeot * 515dba7a9SFrançois Tigeot * Redistribution and use in source and binary forms, with or without 615dba7a9SFrançois Tigeot * modification, are permitted provided that the following conditions 715dba7a9SFrançois Tigeot * are met: 815dba7a9SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 915dba7a9SFrançois Tigeot * notice unmodified, this list of conditions, and the following 1015dba7a9SFrançois Tigeot * disclaimer. 1115dba7a9SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 1215dba7a9SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 1315dba7a9SFrançois Tigeot * documentation and/or other materials provided with the distribution. 1415dba7a9SFrançois Tigeot * 1515dba7a9SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1615dba7a9SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1715dba7a9SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1815dba7a9SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1915dba7a9SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2015dba7a9SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2115dba7a9SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2215dba7a9SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2315dba7a9SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2415dba7a9SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2515dba7a9SFrançois Tigeot */ 2615dba7a9SFrançois Tigeot 27*8b44ed4dSzrj #include <linux/gfp.h> 2815dba7a9SFrançois Tigeot #include <linux/kobject.h> 2915dba7a9SFrançois Tigeot 309286b91eSSascha Wildner extern char *drm_vasprintf(int flags, const char *format, va_list ap); 3115dba7a9SFrançois Tigeot 3215dba7a9SFrançois Tigeot int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, 3315dba7a9SFrançois Tigeot struct kobject *parent, const char *fmt, ...) 3415dba7a9SFrançois Tigeot { 3515dba7a9SFrançois Tigeot va_list ap; 3615dba7a9SFrançois Tigeot 3715dba7a9SFrançois Tigeot kobj->ktype = ktype; 3815dba7a9SFrançois Tigeot kref_init(&kobj->kref); 3915dba7a9SFrançois Tigeot 409286b91eSSascha Wildner va_start(ap, fmt); 4115dba7a9SFrançois Tigeot kobj->name = drm_vasprintf(M_WAITOK, fmt, ap); 429286b91eSSascha Wildner va_end(ap); 4315dba7a9SFrançois Tigeot 4415dba7a9SFrançois Tigeot return 0; 4515dba7a9SFrançois Tigeot } 4615dba7a9SFrançois Tigeot 4715dba7a9SFrançois Tigeot void kobject_release(struct kref *kref) 4815dba7a9SFrançois Tigeot { 4915dba7a9SFrançois Tigeot struct kobject *kobj = container_of(kref, struct kobject, kref); 5015dba7a9SFrançois Tigeot 5115dba7a9SFrançois Tigeot if (kobj->ktype && kobj->ktype->release) 5215dba7a9SFrançois Tigeot kobj->ktype->release(kobj); 5315dba7a9SFrançois Tigeot } 54