mirror of
https://github.com/torvalds/linux.git
synced 2026-11-25 07:52:34 +00:00
Based on 2 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details you should have received a copy of the gnu general public license along with this program if not see http www gnu org licenses this program is free software you can redistribute it and or modify it under the terms of the gnu general public license as published by the free software foundation either version 2 of the license or at your option any later version this program is distributed in the hope that it will be useful but without any warranty without even the implied warranty of merchantability or fitness for a particular purpose see the gnu general public license for more details [based] [from] [clk] [highbank] [c] you should have received a copy of the gnu general public license along with this program if not see http www gnu org licenses extracted by the scancode license scanner the SPDX license identifier GPL-2.0-or-later has been chosen to replace the boilerplate/reference in 355 file(s). Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Kate Stewart <[email protected]> Reviewed-by: Jilayne Lovejoy <[email protected]> Reviewed-by: Steve Winslow <[email protected]> Reviewed-by: Allison Randal <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
86 lines
1.8 KiB
C
86 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Copyright (C) 2011 Instituto Nokia de Tecnologia
|
|
*
|
|
* Authors:
|
|
* Aloisio Almeida Jr <[email protected]>
|
|
* Lauro Ramos Venancio <[email protected]>
|
|
*/
|
|
|
|
#include <linux/nfc.h>
|
|
#include <linux/module.h>
|
|
|
|
#include "nfc.h"
|
|
|
|
static DEFINE_RWLOCK(proto_tab_lock);
|
|
static const struct nfc_protocol *proto_tab[NFC_SOCKPROTO_MAX];
|
|
|
|
static int nfc_sock_create(struct net *net, struct socket *sock, int proto,
|
|
int kern)
|
|
{
|
|
int rc = -EPROTONOSUPPORT;
|
|
|
|
if (net != &init_net)
|
|
return -EAFNOSUPPORT;
|
|
|
|
if (proto < 0 || proto >= NFC_SOCKPROTO_MAX)
|
|
return -EINVAL;
|
|
|
|
read_lock(&proto_tab_lock);
|
|
if (proto_tab[proto] && try_module_get(proto_tab[proto]->owner)) {
|
|
rc = proto_tab[proto]->create(net, sock, proto_tab[proto], kern);
|
|
module_put(proto_tab[proto]->owner);
|
|
}
|
|
read_unlock(&proto_tab_lock);
|
|
|
|
return rc;
|
|
}
|
|
|
|
static const struct net_proto_family nfc_sock_family_ops = {
|
|
.owner = THIS_MODULE,
|
|
.family = PF_NFC,
|
|
.create = nfc_sock_create,
|
|
};
|
|
|
|
int nfc_proto_register(const struct nfc_protocol *nfc_proto)
|
|
{
|
|
int rc;
|
|
|
|
if (nfc_proto->id < 0 || nfc_proto->id >= NFC_SOCKPROTO_MAX)
|
|
return -EINVAL;
|
|
|
|
rc = proto_register(nfc_proto->proto, 0);
|
|
if (rc)
|
|
return rc;
|
|
|
|
write_lock(&proto_tab_lock);
|
|
if (proto_tab[nfc_proto->id])
|
|
rc = -EBUSY;
|
|
else
|
|
proto_tab[nfc_proto->id] = nfc_proto;
|
|
write_unlock(&proto_tab_lock);
|
|
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL(nfc_proto_register);
|
|
|
|
void nfc_proto_unregister(const struct nfc_protocol *nfc_proto)
|
|
{
|
|
write_lock(&proto_tab_lock);
|
|
proto_tab[nfc_proto->id] = NULL;
|
|
write_unlock(&proto_tab_lock);
|
|
|
|
proto_unregister(nfc_proto->proto);
|
|
}
|
|
EXPORT_SYMBOL(nfc_proto_unregister);
|
|
|
|
int __init af_nfc_init(void)
|
|
{
|
|
return sock_register(&nfc_sock_family_ops);
|
|
}
|
|
|
|
void af_nfc_exit(void)
|
|
{
|
|
sock_unregister(PF_NFC);
|
|
}
|