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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright (C) 2011 Instituto Nokia de Tecnologia
  4  *
  5  * Authors:
  6  *    Aloisio Almeida Jr <aloisio.almeida@openbossa.org>
  7  *    Lauro Ramos Venancio <lauro.venancio@openbossa.org>
  8  */
  9 
 10 #include <linux/nfc.h>
 11 #include <linux/module.h>
 12 
 13 #include "nfc.h"
 14 
 15 static DEFINE_RWLOCK(proto_tab_lock);
 16 static const struct nfc_protocol *proto_tab[NFC_SOCKPROTO_MAX];
 17 
 18 static int nfc_sock_create(struct net *net, struct socket *sock, int proto,
 19                            int kern)
 20 {
 21         int rc = -EPROTONOSUPPORT;
 22 
 23         if (net != &init_net)
 24                 return -EAFNOSUPPORT;
 25 
 26         if (proto < 0 || proto >= NFC_SOCKPROTO_MAX)
 27                 return -EINVAL;
 28 
 29         read_lock(&proto_tab_lock);
 30         if (proto_tab[proto] && try_module_get(proto_tab[proto]->owner)) {
 31                 rc = proto_tab[proto]->create(net, sock, proto_tab[proto], kern);
 32                 module_put(proto_tab[proto]->owner);
 33         }
 34         read_unlock(&proto_tab_lock);
 35 
 36         return rc;
 37 }
 38 
 39 static const struct net_proto_family nfc_sock_family_ops = {
 40         .owner  = THIS_MODULE,
 41         .family = PF_NFC,
 42         .create = nfc_sock_create,
 43 };
 44 
 45 int nfc_proto_register(const struct nfc_protocol *nfc_proto)
 46 {
 47         int rc;
 48 
 49         if (nfc_proto->id < 0 || nfc_proto->id >= NFC_SOCKPROTO_MAX)
 50                 return -EINVAL;
 51 
 52         rc = proto_register(nfc_proto->proto, 0);
 53         if (rc)
 54                 return rc;
 55 
 56         write_lock(&proto_tab_lock);
 57         if (proto_tab[nfc_proto->id])
 58                 rc = -EBUSY;
 59         else
 60                 proto_tab[nfc_proto->id] = nfc_proto;
 61         write_unlock(&proto_tab_lock);
 62 
 63         if (rc)
 64                 proto_unregister(nfc_proto->proto);
 65 
 66         return rc;
 67 }
 68 EXPORT_SYMBOL(nfc_proto_register);
 69 
 70 void nfc_proto_unregister(const struct nfc_protocol *nfc_proto)
 71 {
 72         write_lock(&proto_tab_lock);
 73         proto_tab[nfc_proto->id] = NULL;
 74         write_unlock(&proto_tab_lock);
 75 
 76         proto_unregister(nfc_proto->proto);
 77 }
 78 EXPORT_SYMBOL(nfc_proto_unregister);
 79 
 80 int __init af_nfc_init(void)
 81 {
 82         return sock_register(&nfc_sock_family_ops);
 83 }
 84 
 85 void __exit af_nfc_exit(void)
 86 {
 87         sock_unregister(PF_NFC);
 88 }
 89 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php