1*15dba7a9SFrançois Tigeot /* 2*15dba7a9SFrançois Tigeot * Copyright (c) 2018 François Tigeot <ftigeot@wolfpond.org> 3*15dba7a9SFrançois Tigeot * All rights reserved. 4*15dba7a9SFrançois Tigeot * 5*15dba7a9SFrançois Tigeot * Redistribution and use in source and binary forms, with or without 6*15dba7a9SFrançois Tigeot * modification, are permitted provided that the following conditions 7*15dba7a9SFrançois Tigeot * are met: 8*15dba7a9SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 9*15dba7a9SFrançois Tigeot * notice unmodified, this list of conditions, and the following 10*15dba7a9SFrançois Tigeot * disclaimer. 11*15dba7a9SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 12*15dba7a9SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 13*15dba7a9SFrançois Tigeot * documentation and/or other materials provided with the distribution. 14*15dba7a9SFrançois Tigeot * 15*15dba7a9SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16*15dba7a9SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*15dba7a9SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*15dba7a9SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19*15dba7a9SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*15dba7a9SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*15dba7a9SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*15dba7a9SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*15dba7a9SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*15dba7a9SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*15dba7a9SFrançois Tigeot */ 26*15dba7a9SFrançois Tigeot 27*15dba7a9SFrançois Tigeot #include <linux/kobject.h> 28*15dba7a9SFrançois Tigeot 29*15dba7a9SFrançois Tigeot extern char *drm_vasprintf(int flags, const char *format, __va_list ap); 30*15dba7a9SFrançois Tigeot 31*15dba7a9SFrançois Tigeot int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, 32*15dba7a9SFrançois Tigeot struct kobject *parent, const char *fmt, ...) 33*15dba7a9SFrançois Tigeot { 34*15dba7a9SFrançois Tigeot va_list ap; 35*15dba7a9SFrançois Tigeot 36*15dba7a9SFrançois Tigeot kobj->ktype = ktype; 37*15dba7a9SFrançois Tigeot kref_init(&kobj->kref); 38*15dba7a9SFrançois Tigeot 39*15dba7a9SFrançois Tigeot __va_start(ap, fmt); 40*15dba7a9SFrançois Tigeot kobj->name = drm_vasprintf(M_WAITOK, fmt, ap); 41*15dba7a9SFrançois Tigeot __va_end(ap); 42*15dba7a9SFrançois Tigeot 43*15dba7a9SFrançois Tigeot return 0; 44*15dba7a9SFrançois Tigeot } 45*15dba7a9SFrançois Tigeot 46*15dba7a9SFrançois Tigeot void kobject_release(struct kref *kref) 47*15dba7a9SFrançois Tigeot { 48*15dba7a9SFrançois Tigeot struct kobject *kobj = container_of(kref, struct kobject, kref); 49*15dba7a9SFrançois Tigeot 50*15dba7a9SFrançois Tigeot if (kobj->ktype && kobj->ktype->release) 51*15dba7a9SFrançois Tigeot kobj->ktype->release(kobj); 52*15dba7a9SFrançois Tigeot } 53