~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/nfc/af_nfc.c

Version: ~ [ linux-5.13-rc5 ] ~ [ linux-5.12.9 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.42 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.124 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.193 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.235 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.271 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.271 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Copyright (C) 2011 Instituto Nokia de Tecnologia
  3  *
  4  * Authors:
  5  *    Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
  6  *    Lauro Ramos Venancio <lauro.venancio@openbossa.org>
  7  *
  8  * This program is free software; you can redistribute it and/or modify
  9  * it under the terms of the GNU General Public License as published by
 10  * the Free Software Foundation; either version 2 of the License, or
 11  * (at your option) any later version.
 12  *
 13  * This program is distributed in the hope that it will be useful,
 14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16  * GNU General Public License for more details.
 17  *
 18  * You should have received a copy of the GNU General Public License
 19  * along with this program; if not, see <http://www.gnu.org/licenses/>.
 20  */
 21 
 22 #include <linux/nfc.h>
 23 #include <linux/module.h>
 24 
 25 #include "nfc.h"
 26 
 27 static DEFINE_RWLOCK(proto_tab_lock);
 28 static const struct nfc_protocol *proto_tab[NFC_SOCKPROTO_MAX];
 29 
 30 static int nfc_sock_create(struct net *net, struct socket *sock, int proto,
 31                            int kern)
 32 {
 33         int rc = -EPROTONOSUPPORT;
 34 
 35         if (net != &init_net)
 36                 return -EAFNOSUPPORT;
 37 
 38         if (proto < 0 || proto >= NFC_SOCKPROTO_MAX)
 39                 return -EINVAL;
 40 
 41         read_lock(&proto_tab_lock);
 42         if (proto_tab[proto] && try_module_get(proto_tab[proto]->owner)) {
 43                 rc = proto_tab[proto]->create(net, sock, proto_tab[proto], kern);
 44                 module_put(proto_tab[proto]->owner);
 45         }
 46         read_unlock(&proto_tab_lock);
 47 
 48         return rc;
 49 }
 50 
 51 static struct net_proto_family nfc_sock_family_ops = {
 52         .owner  = THIS_MODULE,
 53         .family = PF_NFC,
 54         .create = nfc_sock_create,
 55 };
 56 
 57 int nfc_proto_register(const struct nfc_protocol *nfc_proto)
 58 {
 59         int rc;
 60 
 61         if (nfc_proto->id < 0 || nfc_proto->id >= NFC_SOCKPROTO_MAX)
 62                 return -EINVAL;
 63 
 64         rc = proto_register(nfc_proto->proto, 0);
 65         if (rc)
 66                 return rc;
 67 
 68         write_lock(&proto_tab_lock);
 69         if (proto_tab[nfc_proto->id])
 70                 rc = -EBUSY;
 71         else
 72                 proto_tab[nfc_proto->id] = nfc_proto;
 73         write_unlock(&proto_tab_lock);
 74 
 75         return rc;
 76 }
 77 EXPORT_SYMBOL(nfc_proto_register);
 78 
 79 void nfc_proto_unregister(const struct nfc_protocol *nfc_proto)
 80 {
 81         write_lock(&proto_tab_lock);
 82         proto_tab[nfc_proto->id] = NULL;
 83         write_unlock(&proto_tab_lock);
 84 
 85         proto_unregister(nfc_proto->proto);
 86 }
 87 EXPORT_SYMBOL(nfc_proto_unregister);
 88 
 89 int __init af_nfc_init(void)
 90 {
 91         return sock_register(&nfc_sock_family_ops);
 92 }
 93 
 94 void af_nfc_exit(void)
 95 {
 96         sock_unregister(PF_NFC);
 97 }
 98 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp