mirror of
https://github.com/bolucat/Archive.git
synced 2025-09-26 20:21:35 +08:00
Update On Sat Sep 20 20:32:24 CEST 2025
This commit is contained in:
@@ -315,6 +315,11 @@ include() {
|
||||
done
|
||||
}
|
||||
|
||||
ipcalc() {
|
||||
set -- $(ipcalc.sh "$@")
|
||||
[ $? -eq 0 ] && export -- "$@"
|
||||
}
|
||||
|
||||
find_mtd_index() {
|
||||
local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
|
||||
local INDEX="${PART##mtd}"
|
||||
|
@@ -8,8 +8,8 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=openssl
|
||||
PKG_VERSION:=3.5.2
|
||||
PKG_RELEASE:=2
|
||||
PKG_VERSION:=3.5.3
|
||||
PKG_RELEASE:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
PKG_BUILD_FLAGS:=gc-sections no-lto
|
||||
|
||||
@@ -22,7 +22,7 @@ PKG_SOURCE_URL:= \
|
||||
https://www.openssl.org/source/old/$(PKG_BASE)/ \
|
||||
https://github.com/openssl/openssl/releases/download/$(PKG_NAME)-$(PKG_VERSION)/
|
||||
|
||||
PKG_HASH:=c53a47e5e441c930c3928cf7bf6fb00e5d129b630e0aa873b08258656e7345ec
|
||||
PKG_HASH:=c9489d2abcf943cdc8329a57092331c598a402938054dc3a22218aea8a8ec3bf
|
||||
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
PKG_LICENSE_FILES:=LICENSE.txt
|
||||
|
@@ -1,129 +0,0 @@
|
||||
From c4c92f3e8aff38d75047847ded940e1b3f9b688f Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Thu, 7 Aug 2025 17:50:17 +0100
|
||||
Subject: [PATCH] Don't keep the store open in by_store_ctrl_ex
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Previously #27529 made a change to `by_store_ctrl_ex` in order to open
|
||||
the OSSL_STORE early. The reason given in that PR is:
|
||||
|
||||
"This way, we can call OSSL_STORE_open_ex() in by_store_ctrl_ex(), and
|
||||
get to see possible errors when the URI is loaded"
|
||||
|
||||
That PR then kept the store open until cache_objects is called and then
|
||||
reused it. Unfortunately by the time cache_objects() is called we could be
|
||||
in a multi-threaded scenario where the X509_STORE is being shared by
|
||||
multiple threads. We then get a race condition where multiple threads are
|
||||
all using (and ultimately closing) the same `OSSL_STORE_CTX`.
|
||||
|
||||
The purpose of keeping the `OSSL_STORE` object between by_store_ctrl_ex()
|
||||
and `cache_objects` is presumably an optimisation to avoid having to open
|
||||
the store twice. But this does not work because of the above issue.
|
||||
|
||||
We just take the hit and open it again.
|
||||
|
||||
Fixes #28171
|
||||
|
||||
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/28198)
|
||||
|
||||
(cherry picked from commit 08951fb27306ad9b4365103b8616b8545658ffcc)
|
||||
---
|
||||
crypto/x509/by_store.c | 26 +++++++++++++-------------
|
||||
1 file changed, 13 insertions(+), 13 deletions(-)
|
||||
|
||||
--- a/crypto/x509/by_store.c
|
||||
+++ b/crypto/x509/by_store.c
|
||||
@@ -17,7 +17,6 @@ typedef struct cached_store_st {
|
||||
char *uri;
|
||||
OSSL_LIB_CTX *libctx;
|
||||
char *propq;
|
||||
- OSSL_STORE_CTX *ctx;
|
||||
} CACHED_STORE;
|
||||
|
||||
DEFINE_STACK_OF(CACHED_STORE)
|
||||
@@ -27,14 +26,12 @@ static int cache_objects(X509_LOOKUP *lc
|
||||
const OSSL_STORE_SEARCH *criterion, int depth)
|
||||
{
|
||||
int ok = 0;
|
||||
- OSSL_STORE_CTX *ctx = store->ctx;
|
||||
+ OSSL_STORE_CTX *ctx;
|
||||
X509_STORE *xstore = X509_LOOKUP_get_store(lctx);
|
||||
|
||||
- if (ctx == NULL
|
||||
- && (ctx = OSSL_STORE_open_ex(store->uri, store->libctx, store->propq,
|
||||
- NULL, NULL, NULL, NULL, NULL)) == NULL)
|
||||
+ if ((ctx = OSSL_STORE_open_ex(store->uri, store->libctx, store->propq,
|
||||
+ NULL, NULL, NULL, NULL, NULL)) == NULL)
|
||||
return 0;
|
||||
- store->ctx = ctx;
|
||||
|
||||
/*
|
||||
* We try to set the criterion, but don't care if it was valid or not.
|
||||
@@ -79,7 +76,6 @@ static int cache_objects(X509_LOOKUP *lc
|
||||
substore.uri = (char *)OSSL_STORE_INFO_get0_NAME(info);
|
||||
substore.libctx = store->libctx;
|
||||
substore.propq = store->propq;
|
||||
- substore.ctx = NULL;
|
||||
ok = cache_objects(lctx, &substore, criterion, depth - 1);
|
||||
}
|
||||
} else {
|
||||
@@ -105,7 +101,6 @@ static int cache_objects(X509_LOOKUP *lc
|
||||
break;
|
||||
}
|
||||
OSSL_STORE_close(ctx);
|
||||
- store->ctx = NULL;
|
||||
|
||||
return ok;
|
||||
}
|
||||
@@ -114,7 +109,6 @@ static int cache_objects(X509_LOOKUP *lc
|
||||
static void free_store(CACHED_STORE *store)
|
||||
{
|
||||
if (store != NULL) {
|
||||
- OSSL_STORE_close(store->ctx);
|
||||
OPENSSL_free(store->uri);
|
||||
OPENSSL_free(store->propq);
|
||||
OPENSSL_free(store);
|
||||
@@ -136,6 +130,7 @@ static int by_store_ctrl_ex(X509_LOOKUP
|
||||
if (argp != NULL) {
|
||||
STACK_OF(CACHED_STORE) *stores = X509_LOOKUP_get_method_data(ctx);
|
||||
CACHED_STORE *store = OPENSSL_zalloc(sizeof(*store));
|
||||
+ OSSL_STORE_CTX *sctx;
|
||||
|
||||
if (store == NULL) {
|
||||
return 0;
|
||||
@@ -145,14 +140,20 @@ static int by_store_ctrl_ex(X509_LOOKUP
|
||||
store->libctx = libctx;
|
||||
if (propq != NULL)
|
||||
store->propq = OPENSSL_strdup(propq);
|
||||
- store->ctx = OSSL_STORE_open_ex(argp, libctx, propq, NULL, NULL,
|
||||
- NULL, NULL, NULL);
|
||||
- if (store->ctx == NULL
|
||||
+ /*
|
||||
+ * We open this to check for errors now - so we can report those
|
||||
+ * errors early.
|
||||
+ */
|
||||
+ sctx = OSSL_STORE_open_ex(argp, libctx, propq, NULL, NULL,
|
||||
+ NULL, NULL, NULL);
|
||||
+ if (sctx == NULL
|
||||
|| (propq != NULL && store->propq == NULL)
|
||||
|| store->uri == NULL) {
|
||||
+ OSSL_STORE_close(sctx);
|
||||
free_store(store);
|
||||
return 0;
|
||||
}
|
||||
+ OSSL_STORE_close(sctx);
|
||||
|
||||
if (stores == NULL) {
|
||||
stores = sk_CACHED_STORE_new_null();
|
||||
@@ -174,7 +175,6 @@ static int by_store_ctrl_ex(X509_LOOKUP
|
||||
store.uri = (char *)argp;
|
||||
store.libctx = libctx;
|
||||
store.propq = (char *)propq;
|
||||
- store.ctx = NULL;
|
||||
return cache_objects(ctx, &store, NULL, 0);
|
||||
}
|
||||
default:
|
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (C) 2006-2022 OpenWrt.org
|
||||
# Copyright (C) 2006-2016 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
|
||||
PKG_NAME:=dnsmasq
|
||||
PKG_UPSTREAM_VERSION:=2.91
|
||||
PKG_VERSION:=$(subst test,~~test,$(subst rc,~rc,$(PKG_UPSTREAM_VERSION)))
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.xz
|
||||
PKG_SOURCE_URL:=https://thekelleys.org.uk/dnsmasq/
|
||||
@@ -24,6 +24,7 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_UPSTR
|
||||
|
||||
PKG_INSTALL:=1
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=lto
|
||||
PKG_ASLR_PIE_REGULAR:=1
|
||||
PKG_CONFIG_DEPENDS:= CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dhcp \
|
||||
CONFIG_PACKAGE_dnsmasq_$(BUILD_VARIANT)_dhcpv6 \
|
||||
@@ -108,16 +109,16 @@ define Package/dnsmasq-full/config
|
||||
default n
|
||||
config PACKAGE_dnsmasq_full_auth
|
||||
bool "Build with the facility to act as an authoritative DNS server."
|
||||
default n
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_ipset
|
||||
bool "Build with IPset support."
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_nftset
|
||||
bool "Build with Nftset support."
|
||||
default n
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_conntrack
|
||||
bool "Build with Conntrack support."
|
||||
default n
|
||||
default y
|
||||
config PACKAGE_dnsmasq_full_noid
|
||||
bool "Build with NO_ID. (hide *.bind pseudo domain)"
|
||||
default n
|
||||
@@ -133,9 +134,6 @@ endef
|
||||
Package/dnsmasq-dhcpv6/conffiles = $(Package/dnsmasq/conffiles)
|
||||
Package/dnsmasq-full/conffiles = $(Package/dnsmasq/conffiles)
|
||||
|
||||
TARGET_CFLAGS += -flto
|
||||
TARGET_LDFLAGS += -flto=jobserver
|
||||
|
||||
COPTS = -DHAVE_UBUS -DHAVE_POLL_H \
|
||||
$(if $(CONFIG_IPV6),,-DNO_IPV6)
|
||||
|
||||
|
@@ -8,6 +8,15 @@ json_init
|
||||
json_add_array env
|
||||
hotplugobj=""
|
||||
|
||||
oldIFS=$IFS
|
||||
IFS=$'\n'
|
||||
for var in $(env); do
|
||||
if [ "${var}" != "${var#DNSMASQ_}" ]; then
|
||||
json_add_string "" "${var%%=*}=${var#*=}"
|
||||
fi
|
||||
done
|
||||
IFS=$oldIFS
|
||||
|
||||
case "$1" in
|
||||
add | del | old | arp-add | arp-del)
|
||||
json_add_string "" "MACADDR=$2"
|
||||
|
@@ -10,7 +10,7 @@ config dnsmasq
|
||||
option domain 'lan'
|
||||
option expandhosts 1
|
||||
option nonegcache 0
|
||||
option cachesize 8192
|
||||
option cachesize 1000
|
||||
option authoritative 1
|
||||
option readethers 1
|
||||
option leasefile '/tmp/dhcp.leases'
|
||||
|
@@ -12,6 +12,7 @@ ADD_WAN_FQDN=0
|
||||
ADD_LOCAL_FQDN=""
|
||||
|
||||
BASECONFIGFILE="/var/etc/dnsmasq.conf"
|
||||
EXTRACONFFILE="extraconfig.conf"
|
||||
BASEHOSTFILE="/tmp/hosts/dhcp"
|
||||
TRUSTANCHORSFILE="/usr/share/dnsmasq/trust-anchors.conf"
|
||||
TIMEVALIDFILE="/var/state/dnsmasqsec"
|
||||
@@ -19,7 +20,7 @@ BASEDHCPSTAMPFILE="/var/run/dnsmasq"
|
||||
DHCPBOGUSHOSTNAMEFILE="/usr/share/dnsmasq/dhcpbogushostname.conf"
|
||||
RFC6761FILE="/usr/share/dnsmasq/rfc6761.conf"
|
||||
DHCPSCRIPT="/usr/lib/dnsmasq/dhcp-script.sh"
|
||||
DHCPSCRIPT_DEPENDS="/usr/share/libubox/jshn.sh /usr/bin/jshn /bin/ubus"
|
||||
DHCPSCRIPT_DEPENDS="/usr/share/libubox/jshn.sh /usr/bin/jshn /bin/ubus /usr/bin/env"
|
||||
|
||||
DNSMASQ_DHCP_VER=4
|
||||
|
||||
@@ -33,6 +34,7 @@ dnsmasq_ignore_opt() {
|
||||
[ "${dnsmasq_features#* DNSSEC }" = "$dnsmasq_features" ] || dnsmasq_has_dnssec=1
|
||||
[ "${dnsmasq_features#* TFTP }" = "$dnsmasq_features" ] || dnsmasq_has_tftp=1
|
||||
[ "${dnsmasq_features#* ipset }" = "$dnsmasq_features" ] || dnsmasq_has_ipset=1
|
||||
[ "${dnsmasq_features#* nftset }" = "$dnsmasq_features" ] || dnsmasq_has_nftset=1
|
||||
fi
|
||||
|
||||
case "$opt" in
|
||||
@@ -55,6 +57,8 @@ dnsmasq_ignore_opt() {
|
||||
[ -z "$dnsmasq_has_tftp" ] ;;
|
||||
ipset)
|
||||
[ -z "$dnsmasq_has_ipset" ] ;;
|
||||
nftset)
|
||||
[ -z "$dnsmasq_has_nftset" ] ;;
|
||||
*)
|
||||
return 1
|
||||
esac
|
||||
@@ -65,7 +69,7 @@ xappend() {
|
||||
local opt="${value%%=*}"
|
||||
|
||||
if ! dnsmasq_ignore_opt "$opt"; then
|
||||
echo "$value" >>$CONFIGFILE_TMP
|
||||
echo "$value" >>"$CONFIGFILE_TMP"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -169,10 +173,6 @@ append_address() {
|
||||
xappend "--address=$1"
|
||||
}
|
||||
|
||||
append_ipset() {
|
||||
xappend "--ipset=$1"
|
||||
}
|
||||
|
||||
append_connmark_allowlist() {
|
||||
xappend "--connmark-allowlist=$1"
|
||||
}
|
||||
@@ -205,8 +205,12 @@ ismounted() {
|
||||
return 1
|
||||
}
|
||||
|
||||
append_addnhosts() {
|
||||
append_extramount() {
|
||||
ismounted "$1" || append EXTRA_MOUNT "$1"
|
||||
}
|
||||
|
||||
append_addnhosts() {
|
||||
append_extramount "$1"
|
||||
xappend "--addn-hosts=$1"
|
||||
}
|
||||
|
||||
@@ -222,6 +226,14 @@ append_interface_name() {
|
||||
xappend "--interface-name=$1,$2"
|
||||
}
|
||||
|
||||
append_filter_rr() {
|
||||
xappend "--filter-rr=$1"
|
||||
}
|
||||
|
||||
append_cache_rr() {
|
||||
xappend "--cache-rr=$1"
|
||||
}
|
||||
|
||||
filter_dnsmasq() {
|
||||
local cfg="$1" func="$2" match_cfg="$3" found_cfg
|
||||
|
||||
@@ -350,7 +362,7 @@ dhcp_host_add() {
|
||||
|
||||
config_get_bool dns "$cfg" dns 0
|
||||
[ "$dns" = "1" ] && [ -n "$ip" ] && [ -n "$name" ] && {
|
||||
echo "$ip $name${DOMAIN:+.$DOMAIN}" >> $HOSTFILE_TMP
|
||||
echo "$ip $name${DOMAIN:+.$DOMAIN}" >> "$HOSTFILE_TMP"
|
||||
}
|
||||
|
||||
config_get mac "$cfg" mac
|
||||
@@ -499,14 +511,13 @@ dhcp_boot_add() {
|
||||
|
||||
[ -n "$serveraddress" ] && [ ! -n "$servername" ] && return 0
|
||||
|
||||
xappend "--dhcp-boot=${networkid:+net:$networkid,}${filename}${servername:+,$servername}${serveraddress:+,$serveraddress}"
|
||||
xappend "--dhcp-boot=${networkid:+tag:$networkid,}${filename}${servername:+,$servername}${serveraddress:+,$serveraddress}"
|
||||
|
||||
config_get_bool force "$cfg" force 0
|
||||
|
||||
dhcp_option_add "$cfg" "$networkid" "$force"
|
||||
}
|
||||
|
||||
|
||||
dhcp_add() {
|
||||
local cfg="$1"
|
||||
local dhcp6range="::"
|
||||
@@ -537,8 +548,13 @@ dhcp_add() {
|
||||
# Do not support non-static interfaces for now
|
||||
[ static = "$proto" ] || return 0
|
||||
|
||||
ipaddr="${subnet%%/*}"
|
||||
prefix_or_netmask="${subnet##*/}"
|
||||
|
||||
# Override interface netmask with dhcp config if applicable
|
||||
config_get netmask "$cfg" netmask "${subnet##*/}"
|
||||
config_get netmask "$cfg" netmask
|
||||
|
||||
[ -n "$netmask" ] && prefix_or_netmask="$netmask"
|
||||
|
||||
#check for an already active dhcp server on the interface, unless 'force' is set
|
||||
config_get_bool force "$cfg" force 0
|
||||
@@ -554,6 +570,8 @@ dhcp_add() {
|
||||
config_get leasetime "$cfg" leasetime 12h
|
||||
config_get options "$cfg" options
|
||||
config_get_bool dynamicdhcp "$cfg" dynamicdhcp 1
|
||||
config_get_bool dynamicdhcpv4 "$cfg" dynamicdhcpv4 $dynamicdhcp
|
||||
config_get_bool dynamicdhcpv6 "$cfg" dynamicdhcpv6 $dynamicdhcp
|
||||
|
||||
config_get dhcpv4 "$cfg" dhcpv4
|
||||
config_get dhcpv6 "$cfg" dhcpv6
|
||||
@@ -578,25 +596,30 @@ dhcp_add() {
|
||||
|
||||
nettag="${networkid:+set:${networkid},}"
|
||||
|
||||
if [ "$limit" -gt 0 ] ; then
|
||||
limit=$((limit-1))
|
||||
# make sure the DHCP range is not empty
|
||||
if [ "$dhcpv4" != "disabled" ]; then
|
||||
unset START
|
||||
unset END
|
||||
unset NETMASK
|
||||
ipcalc "$ipaddr/$prefix_or_netmask" "$start" "$limit"
|
||||
|
||||
if [ -z "$START" ] || [ -z "$END" ] || [ -z "$NETMASK" ]; then
|
||||
logger -t dnsmasq \
|
||||
"unable to set dhcp-range for dhcp uci config section '$cfg'" \
|
||||
"on interface '$ifname', please check your config"
|
||||
else
|
||||
[ "$dynamicdhcpv4" = "0" ] && END="static"
|
||||
xappend "--dhcp-range=$tags$nettag$START,$END,$NETMASK,$leasetime${options:+ $options}"
|
||||
fi
|
||||
fi
|
||||
|
||||
eval "$(ipcalc.sh "${subnet%%/*}" $netmask $start $limit)"
|
||||
|
||||
if [ "$dynamicdhcp" = "0" ] ; then
|
||||
END="static"
|
||||
if [ "$dynamicdhcpv6" = "0" ] ; then
|
||||
dhcp6range="::,static"
|
||||
else
|
||||
dhcp6range="::1000,::ffff"
|
||||
fi
|
||||
|
||||
|
||||
if [ "$dhcpv4" != "disabled" ] ; then
|
||||
xappend "--dhcp-range=$tags$nettag$START,$END,$NETMASK,$leasetime${options:+ $options}"
|
||||
fi
|
||||
|
||||
|
||||
if [ $DNSMASQ_DHCP_VER -eq 6 ] && [ "$ra" = "server" ] ; then
|
||||
# Note: dnsmasq cannot just be a DHCPv6 server (all-in-1)
|
||||
# and let some other machine(s) send RA pointing to it.
|
||||
@@ -709,7 +732,7 @@ dhcp_domain_add() {
|
||||
record="${record:+$record }$name"
|
||||
done
|
||||
|
||||
echo "$ip $record" >> $HOSTFILE_TMP
|
||||
echo "$ip $record" >> "$HOSTFILE_TMP"
|
||||
}
|
||||
|
||||
dhcp_srv_add() {
|
||||
@@ -783,6 +806,29 @@ dhcp_hostrecord_add() {
|
||||
xappend "--host-record=$record"
|
||||
}
|
||||
|
||||
dhcp_dnsrr_add() {
|
||||
#This adds arbitrary resource record types (of IN class) whose optional data must be hex
|
||||
local cfg="$1"
|
||||
local rrname rrnumber hexdata
|
||||
|
||||
config_get rrname "$cfg" rrname
|
||||
[ -n "$rrname" ] || return 0
|
||||
|
||||
config_get rrnumber "$cfg" rrnumber
|
||||
[ -n "$rrnumber" ] && [ "$rrnumber" -gt 0 ] || return 0
|
||||
|
||||
config_get hexdata "$cfg" hexdata
|
||||
|
||||
# dnsmasq accepts colon XX:XX:.., space XX XX .., or contiguous XXXX.. hex forms or mixtures thereof
|
||||
if [ -n "${hexdata//[0-9a-fA-F\:\ ]/}" ]; then
|
||||
# is invalid hex literal
|
||||
echo "dnsmasq: \"$hexdata\" is malformed hexadecimal (separate hex with colon, space or not at all)." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
xappend "--dns-rr=${rrname},${rrnumber}${hexdata:+,$hexdata}"
|
||||
}
|
||||
|
||||
dhcp_relay_add() {
|
||||
local cfg="$1"
|
||||
local local_addr server_addr interface
|
||||
@@ -804,30 +850,61 @@ dhcp_relay_add() {
|
||||
|
||||
dnsmasq_ipset_add() {
|
||||
local cfg="$1"
|
||||
local ipsets
|
||||
local ipsets nftsets domains
|
||||
|
||||
add_ipset() {
|
||||
ipsets="${ipsets:+$ipsets,}$1"
|
||||
}
|
||||
|
||||
add_domain() {
|
||||
xappend "--ipset=/$1/$ipsets"
|
||||
add_nftset() {
|
||||
local IFS=,
|
||||
for set in $1; do
|
||||
local fam="$family"
|
||||
[ -n "$fam" ] || fam=$(echo "$set" | sed -nre \
|
||||
's#^.*[^0-9]([46])$|^.*[-_]([46])[-_].*$|^([46])[^0-9].*$#\1\2\3#p')
|
||||
[ -n "$fam" ] || \
|
||||
fam=$(nft -t list set "$table_family" "$table" "$set" 2>&1 | sed -nre \
|
||||
's#^\t\ttype .*\bipv([46])_addr\b.*$#\1#p')
|
||||
|
||||
[ -n "$fam" ] || \
|
||||
logger -t dnsmasq "Cannot infer address family from non-existent nftables set '$set'"
|
||||
|
||||
nftsets="${nftsets:+$nftsets,}${fam:+$fam#}$table_family#$table#$set"
|
||||
done
|
||||
}
|
||||
|
||||
config_list_foreach "$cfg" "name" add_ipset
|
||||
add_domain() {
|
||||
# leading '/' is expected
|
||||
domains="$domains/$1"
|
||||
}
|
||||
|
||||
if [ -z "$ipsets" ]; then
|
||||
config_get table "$cfg" table 'fw4'
|
||||
config_get table_family "$cfg" table_family 'inet'
|
||||
if [ "$table_family" = "ip" ] ; then
|
||||
family="4"
|
||||
elif [ "$table_family" = "ip6" ] ; then
|
||||
family="6"
|
||||
else
|
||||
config_get family "$cfg" family
|
||||
fi
|
||||
|
||||
config_list_foreach "$cfg" "name" add_ipset
|
||||
config_list_foreach "$cfg" "name" add_nftset
|
||||
config_list_foreach "$cfg" "domain" add_domain
|
||||
|
||||
if [ -z "$ipsets" ] || [ -z "$nftsets" ] || [ -z "$domains" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
config_list_foreach "$cfg" "domain" add_domain
|
||||
xappend "--ipset=$domains/$ipsets"
|
||||
xappend "--nftset=$domains/$nftsets"
|
||||
}
|
||||
|
||||
dnsmasq_start()
|
||||
{
|
||||
local cfg="$1"
|
||||
local disabled user_dhcpscript
|
||||
local resolvfile resolvdir localuse=0
|
||||
local disabled user_dhcpscript logfacility
|
||||
local resolvfile resolvdir localuse=1
|
||||
|
||||
config_get_bool disabled "$cfg" disabled 0
|
||||
[ "$disabled" -gt 0 ] && return 0
|
||||
@@ -846,13 +923,13 @@ dnsmasq_start()
|
||||
# before we can call xappend
|
||||
umask u=rwx,g=rx,o=rx
|
||||
mkdir -p /var/run/dnsmasq/
|
||||
mkdir -p $(dirname $CONFIGFILE)
|
||||
mkdir -p "$(dirname "$CONFIGFILE")"
|
||||
mkdir -p "$HOSTFILE_DIR"
|
||||
mkdir -p /var/lib/misc
|
||||
chown dnsmasq:dnsmasq /var/run/dnsmasq
|
||||
|
||||
echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE_TMP
|
||||
echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE_TMP
|
||||
echo "# auto-generated config file from /etc/config/dhcp" > "$CONFIGFILE_TMP"
|
||||
echo "# auto-generated config file from /etc/config/dhcp" > "$HOSTFILE_TMP"
|
||||
|
||||
local dnsmasqconffile="/etc/dnsmasq.${cfg}.conf"
|
||||
if [ ! -r "$dnsmasqconffile" ]; then
|
||||
@@ -938,11 +1015,14 @@ dnsmasq_start()
|
||||
append_bool "$cfg" rapidcommit "--dhcp-rapid-commit"
|
||||
append_bool "$cfg" scriptarp "--script-arp"
|
||||
|
||||
# deprecate or remove filter-X in favor of filter-rr?
|
||||
append_bool "$cfg" filter_aaaa "--filter-AAAA"
|
||||
append_bool "$cfg" filter_a "--filter-A"
|
||||
config_list_foreach "$cfg" filter_rr append_filter_rr
|
||||
config_list_foreach "$cfg" cache_rr append_cache_rr
|
||||
|
||||
append_parm "$cfg" logfacility "--log-facility"
|
||||
|
||||
config_get logfacility "$cfg" "logfacility"
|
||||
append_parm "$cfg" cachesize "--cache-size"
|
||||
append_parm "$cfg" dnsforwardmax "--dns-forward-max"
|
||||
append_parm "$cfg" port "--port"
|
||||
@@ -957,7 +1037,6 @@ dnsmasq_start()
|
||||
config_list_foreach "$cfg" "server" append_server
|
||||
config_list_foreach "$cfg" "rev_server" append_rev_server
|
||||
config_list_foreach "$cfg" "address" append_address
|
||||
config_list_foreach "$cfg" "ipset" append_ipset
|
||||
|
||||
local connmark_allowlist_enable
|
||||
config_get connmark_allowlist_enable "$cfg" connmark_allowlist_enable 0
|
||||
@@ -981,7 +1060,14 @@ dnsmasq_start()
|
||||
config_list_foreach "$cfg" "addnhosts" append_addnhosts
|
||||
config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
|
||||
append_parm "$cfg" "leasefile" "--dhcp-leasefile" "/tmp/dhcp.leases"
|
||||
append_parm "$cfg" "serversfile" "--servers-file"
|
||||
|
||||
local serversfile
|
||||
config_get serversfile "$cfg" "serversfile"
|
||||
[ -n "$serversfile" ] && {
|
||||
xappend "--servers-file=$serversfile"
|
||||
append EXTRA_MOUNT "$serversfile"
|
||||
}
|
||||
|
||||
append_parm "$cfg" "tftp_root" "--tftp-root"
|
||||
append_parm "$cfg" "dhcp_boot" "--dhcp-boot"
|
||||
append_parm "$cfg" "local_ttl" "--local-ttl"
|
||||
@@ -1018,7 +1104,7 @@ dnsmasq_start()
|
||||
config_get resolvfile "$cfg" resolvfile /tmp/resolv.conf.d/resolv.conf.auto
|
||||
[ -n "$resolvfile" ] && [ ! -e "$resolvfile" ] && touch "$resolvfile"
|
||||
xappend "--resolv-file=$resolvfile"
|
||||
[ "$resolvfile" = "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=1
|
||||
[ "$resolvfile" != "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=0
|
||||
resolvdir="$(dirname "$resolvfile")"
|
||||
fi
|
||||
config_get_bool localuse "$cfg" localuse "$localuse"
|
||||
@@ -1067,6 +1153,9 @@ dnsmasq_start()
|
||||
[ "$addmac" = "1" ] && addmac=
|
||||
xappend "--add-mac${addmac:+="$addmac"}"
|
||||
}
|
||||
append_bool "$cfg" stripmac "--strip-mac"
|
||||
append_parm "$cfg" addsubnet "--add-subnet"
|
||||
append_bool "$cfg" stripsubnet "--strip-subnet"
|
||||
|
||||
dhcp_option_add "$cfg" "" 0
|
||||
dhcp_option_add "$cfg" "" 2
|
||||
@@ -1080,7 +1169,7 @@ dnsmasq_start()
|
||||
[ ! -d "$dnsmasqconfdir" ] && mkdir -p $dnsmasqconfdir
|
||||
xappend "--user=dnsmasq"
|
||||
xappend "--group=dnsmasq"
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
|
||||
config_get_bool enable_tftp "$cfg" enable_tftp 0
|
||||
[ "$enable_tftp" -gt 0 ] && {
|
||||
@@ -1089,7 +1178,7 @@ dnsmasq_start()
|
||||
}
|
||||
|
||||
config_foreach filter_dnsmasq host dhcp_host_add "$cfg"
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
|
||||
config_get_bool dhcpbogushostname "$cfg" dhcpbogushostname 1
|
||||
[ "$dhcpbogushostname" -gt 0 ] && {
|
||||
@@ -1108,12 +1197,13 @@ dnsmasq_start()
|
||||
config_foreach filter_dnsmasq match dhcp_match_add "$cfg"
|
||||
config_foreach filter_dnsmasq domain dhcp_domain_add "$cfg"
|
||||
config_foreach filter_dnsmasq hostrecord dhcp_hostrecord_add "$cfg"
|
||||
config_foreach filter_dnsmasq dnsrr dhcp_dnsrr_add "$cfg"
|
||||
[ -n "$BOOT" ] || config_foreach filter_dnsmasq relay dhcp_relay_add "$cfg"
|
||||
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
config_foreach filter_dnsmasq srvhost dhcp_srv_add "$cfg"
|
||||
config_foreach filter_dnsmasq mxhost dhcp_mx_add "$cfg"
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
|
||||
config_get_bool boguspriv "$cfg" boguspriv 1
|
||||
[ "$boguspriv" -gt 0 ] && {
|
||||
@@ -1135,16 +1225,16 @@ dnsmasq_start()
|
||||
fi
|
||||
|
||||
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg"
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg"
|
||||
echo >> $CONFIGFILE_TMP
|
||||
echo >> "$CONFIGFILE_TMP"
|
||||
|
||||
mv -f $CONFIGFILE_TMP $CONFIGFILE
|
||||
mv -f $HOSTFILE_TMP $HOSTFILE
|
||||
mv -f "$CONFIGFILE_TMP" "$CONFIGFILE"
|
||||
mv -f "$HOSTFILE_TMP" "$HOSTFILE"
|
||||
|
||||
[ "$localuse" -gt 0 ] && {
|
||||
rm -f /tmp/resolv.conf
|
||||
@@ -1158,18 +1248,30 @@ dnsmasq_start()
|
||||
done
|
||||
}
|
||||
|
||||
config_list_foreach "$cfg" addnmount append_extramount
|
||||
|
||||
procd_open_instance $cfg
|
||||
procd_set_param command $PROG -C $CONFIGFILE -k -x /var/run/dnsmasq/dnsmasq."${cfg}".pid
|
||||
procd_set_param file $CONFIGFILE
|
||||
[ -n "$user_dhcpscript" ] && procd_set_param env USER_DHCPSCRIPT="$user_dhcpscript"
|
||||
procd_set_param respawn
|
||||
|
||||
local instance_ifc instance_netdev
|
||||
config_get instance_ifc "$cfg" interface
|
||||
[ -n "$instance_ifc" ] && network_get_device instance_netdev "$instance_ifc" &&
|
||||
[ -n "$instance_netdev" ] && procd_set_param netdev $instance_netdev
|
||||
|
||||
procd_add_jail dnsmasq ubus log
|
||||
procd_add_jail_mount $CONFIGFILE $DHCPBOGUSHOSTNAMEFILE $DHCPSCRIPT $DHCPSCRIPT_DEPENDS
|
||||
procd_add_jail_mount $EXTRA_MOUNT $RFC6761FILE $TRUSTANCHORSFILE
|
||||
procd_add_jail_mount $dnsmasqconffile $dnsmasqconfdir $resolvdir $user_dhcpscript
|
||||
procd_add_jail_mount /etc/passwd /etc/group /etc/TZ /etc/hosts /etc/ethers
|
||||
procd_add_jail_mount_rw /var/run/dnsmasq/ $leasefile
|
||||
case "$logfacility" in */*)
|
||||
[ ! -e "$logfacility" ] && touch "$logfacility"
|
||||
procd_add_jail_mount_rw "$logfacility"
|
||||
esac
|
||||
[ -e "$hostsfile" ] && procd_add_jail_mount $hostsfile
|
||||
|
||||
procd_close_instance
|
||||
}
|
||||
@@ -1177,12 +1279,12 @@ dnsmasq_start()
|
||||
dnsmasq_stop()
|
||||
{
|
||||
local cfg="$1"
|
||||
local noresolv resolvfile localuse=0
|
||||
local noresolv resolvfile localuse=1
|
||||
|
||||
config_get_bool noresolv "$cfg" noresolv 0
|
||||
config_get resolvfile "$cfg" "resolvfile"
|
||||
|
||||
[ "$noresolv" = 0 ] && [ "$resolvfile" = "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=1
|
||||
[ "$noresolv" = 0 ] && [ "$resolvfile" != "/tmp/resolv.conf.d/resolv.conf.auto" ] && localuse=0
|
||||
config_get_bool localuse "$cfg" localuse "$localuse"
|
||||
[ "$localuse" -gt 0 ] && ln -sf "/tmp/resolv.conf.d/resolv.conf.auto" /tmp/resolv.conf
|
||||
|
||||
@@ -1191,10 +1293,11 @@ dnsmasq_stop()
|
||||
|
||||
add_interface_trigger()
|
||||
{
|
||||
local interface ignore
|
||||
local interface ifname ignore
|
||||
|
||||
config_get interface "$1" interface
|
||||
config_get_bool ignore "$1" ignore 0
|
||||
network_get_device ifname "$interface" || ignore=0
|
||||
|
||||
[ -n "$interface" ] && [ $ignore -eq 0 ] && procd_add_interface_trigger "interface.*" "$interface" /etc/init.d/dnsmasq reload
|
||||
}
|
||||
|
@@ -275,4 +275,4 @@
|
||||
+
|
||||
void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface)
|
||||
{
|
||||
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
||||
struct ubus_context *ubus = (struct ubus_context *)daemon->ubus;
|
||||
|
@@ -0,0 +1,27 @@
|
||||
From 6cb137c7e99f8307f1f0fcccb1896f2d3b0651d3 Mon Sep 17 00:00:00 2001
|
||||
From: Heiko Stuebner <heiko@sntech.de>
|
||||
Date: Fri, 6 Sep 2024 10:25:08 +0200
|
||||
Subject: clk: clk-gpio: update documentation for gpio-gate clock
|
||||
|
||||
The main documentation block seems to be from a time before the driver
|
||||
handled sleeping and non-sleeping gpios and with that change it seems
|
||||
updating the doc was overlooked. So do that now.
|
||||
|
||||
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
|
||||
Link: https://lore.kernel.org/r/20240906082511.2963890-3-heiko@sntech.de
|
||||
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
|
||||
|
||||
--- a/drivers/clk/clk-gpio.c
|
||||
+++ b/drivers/clk/clk-gpio.c
|
||||
@@ -22,8 +22,9 @@
|
||||
* DOC: basic gpio gated clock which can be enabled and disabled
|
||||
* with gpio output
|
||||
* Traits of this clock:
|
||||
- * prepare - clk_(un)prepare only ensures parent is (un)prepared
|
||||
- * enable - clk_enable and clk_disable are functional & control gpio
|
||||
+ * prepare - clk_(un)prepare are functional and control a gpio that can sleep
|
||||
+ * enable - clk_enable and clk_disable are functional & control
|
||||
+ * non-sleeping gpio
|
||||
* rate - inherits rate from parent. No clk_set_rate support
|
||||
* parent - fixed parent. No clk_set_parent support
|
||||
*/
|
@@ -0,0 +1,44 @@
|
||||
From 36abe81d9c3fa200a57ef2363e93a2991e387e19 Mon Sep 17 00:00:00 2001
|
||||
From: Heiko Stuebner <heiko@sntech.de>
|
||||
Date: Fri, 6 Sep 2024 10:25:09 +0200
|
||||
Subject: clk: clk-gpio: use dev_err_probe for gpio-get failure
|
||||
|
||||
This is a real driver and dev_err_probe will hide the distinction between
|
||||
EPROBE_DEFER and other errors automatically, so there is no need to
|
||||
open-code this.
|
||||
|
||||
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
|
||||
Link: https://lore.kernel.org/r/20240906082511.2963890-4-heiko@sntech.de
|
||||
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
|
||||
|
||||
--- a/drivers/clk/clk-gpio.c
|
||||
+++ b/drivers/clk/clk-gpio.c
|
||||
@@ -200,7 +200,6 @@ static int gpio_clk_driver_probe(struct
|
||||
struct gpio_desc *gpiod;
|
||||
struct clk_hw *hw;
|
||||
bool is_mux;
|
||||
- int ret;
|
||||
|
||||
is_mux = of_device_is_compatible(node, "gpio-mux-clock");
|
||||
|
||||
@@ -212,17 +211,9 @@ static int gpio_clk_driver_probe(struct
|
||||
|
||||
gpio_name = is_mux ? "select" : "enable";
|
||||
gpiod = devm_gpiod_get(dev, gpio_name, GPIOD_OUT_LOW);
|
||||
- if (IS_ERR(gpiod)) {
|
||||
- ret = PTR_ERR(gpiod);
|
||||
- if (ret == -EPROBE_DEFER)
|
||||
- pr_debug("%pOFn: %s: GPIOs not yet available, retry later\n",
|
||||
- node, __func__);
|
||||
- else
|
||||
- pr_err("%pOFn: %s: Can't get '%s' named GPIO property\n",
|
||||
- node, __func__,
|
||||
- gpio_name);
|
||||
- return ret;
|
||||
- }
|
||||
+ if (IS_ERR(gpiod))
|
||||
+ return dev_err_probe(dev, PTR_ERR(gpiod),
|
||||
+ "Can't get '%s' named GPIO property\n", gpio_name);
|
||||
|
||||
if (is_mux)
|
||||
hw = clk_hw_register_gpio_mux(dev, gpiod);
|
@@ -0,0 +1,229 @@
|
||||
From 4940071d962827467f7297be3b874c96186ca0b7 Mon Sep 17 00:00:00 2001
|
||||
From: Heiko Stuebner <heiko@sntech.de>
|
||||
Date: Fri, 6 Sep 2024 10:25:10 +0200
|
||||
Subject: clk: clk-gpio: add driver for gated-fixed-clocks
|
||||
|
||||
In contrast to fixed clocks that are described as ungateable, boards
|
||||
sometimes use additional oscillators for things like PCIe reference
|
||||
clocks, that need actual supplies to get enabled and enable-gpios to be
|
||||
toggled for them to work.
|
||||
|
||||
This adds a driver for those generic gated-fixed-clocks
|
||||
that can show up in schematics looking like
|
||||
|
||||
----------------
|
||||
Enable - | 100MHz,3.3V, | - VDD
|
||||
| 3225 |
|
||||
GND - | | - OUT
|
||||
----------------
|
||||
|
||||
The new driver gets grouped together with the existing gpio-gate and
|
||||
gpio-mux, as it for one re-uses a lot of the gpio-gate functions
|
||||
and also in its core it's just another gpio-controlled clock, just
|
||||
with a fixed rate and a regulator-supply added in.
|
||||
|
||||
The regulator-API provides function stubs for the !CONFIG_REGULATOR case,
|
||||
so no special handling is necessary.
|
||||
|
||||
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
|
||||
Link: https://lore.kernel.org/r/20240906082511.2963890-5-heiko@sntech.de
|
||||
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
|
||||
|
||||
--- a/drivers/clk/clk-gpio.c
|
||||
+++ b/drivers/clk/clk-gpio.c
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <linux/device.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
+#include <linux/regulator/consumer.h>
|
||||
|
||||
/**
|
||||
* DOC: basic gpio gated clock which can be enabled and disabled
|
||||
@@ -239,3 +240,187 @@ static struct platform_driver gpio_clk_d
|
||||
},
|
||||
};
|
||||
builtin_platform_driver(gpio_clk_driver);
|
||||
+
|
||||
+/**
|
||||
+ * DOC: gated fixed clock, controlled with a gpio output and a regulator
|
||||
+ * Traits of this clock:
|
||||
+ * prepare - clk_prepare and clk_unprepare are function & control regulator
|
||||
+ * optionally a gpio that can sleep
|
||||
+ * enable - clk_enable and clk_disable are functional & control gpio
|
||||
+ * rate - rate is fixed and set on clock registration
|
||||
+ * parent - fixed clock is a root clock and has no parent
|
||||
+ */
|
||||
+
|
||||
+/**
|
||||
+ * struct clk_gated_fixed - Gateable fixed rate clock
|
||||
+ * @clk_gpio: instance of clk_gpio for gate-gpio
|
||||
+ * @supply: supply regulator
|
||||
+ * @rate: fixed rate
|
||||
+ */
|
||||
+struct clk_gated_fixed {
|
||||
+ struct clk_gpio clk_gpio;
|
||||
+ struct regulator *supply;
|
||||
+ unsigned long rate;
|
||||
+};
|
||||
+
|
||||
+#define to_clk_gated_fixed(_clk_gpio) container_of(_clk_gpio, struct clk_gated_fixed, clk_gpio)
|
||||
+
|
||||
+static unsigned long clk_gated_fixed_recalc_rate(struct clk_hw *hw,
|
||||
+ unsigned long parent_rate)
|
||||
+{
|
||||
+ return to_clk_gated_fixed(to_clk_gpio(hw))->rate;
|
||||
+}
|
||||
+
|
||||
+static int clk_gated_fixed_prepare(struct clk_hw *hw)
|
||||
+{
|
||||
+ struct clk_gated_fixed *clk = to_clk_gated_fixed(to_clk_gpio(hw));
|
||||
+
|
||||
+ if (!clk->supply)
|
||||
+ return 0;
|
||||
+
|
||||
+ return regulator_enable(clk->supply);
|
||||
+}
|
||||
+
|
||||
+static void clk_gated_fixed_unprepare(struct clk_hw *hw)
|
||||
+{
|
||||
+ struct clk_gated_fixed *clk = to_clk_gated_fixed(to_clk_gpio(hw));
|
||||
+
|
||||
+ if (!clk->supply)
|
||||
+ return;
|
||||
+
|
||||
+ regulator_disable(clk->supply);
|
||||
+}
|
||||
+
|
||||
+static int clk_gated_fixed_is_prepared(struct clk_hw *hw)
|
||||
+{
|
||||
+ struct clk_gated_fixed *clk = to_clk_gated_fixed(to_clk_gpio(hw));
|
||||
+
|
||||
+ if (!clk->supply)
|
||||
+ return true;
|
||||
+
|
||||
+ return regulator_is_enabled(clk->supply);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Fixed gated clock with non-sleeping gpio.
|
||||
+ *
|
||||
+ * Prepare operation turns on the supply regulator
|
||||
+ * and the enable operation switches the enable-gpio.
|
||||
+ */
|
||||
+static const struct clk_ops clk_gated_fixed_ops = {
|
||||
+ .prepare = clk_gated_fixed_prepare,
|
||||
+ .unprepare = clk_gated_fixed_unprepare,
|
||||
+ .is_prepared = clk_gated_fixed_is_prepared,
|
||||
+ .enable = clk_gpio_gate_enable,
|
||||
+ .disable = clk_gpio_gate_disable,
|
||||
+ .is_enabled = clk_gpio_gate_is_enabled,
|
||||
+ .recalc_rate = clk_gated_fixed_recalc_rate,
|
||||
+};
|
||||
+
|
||||
+static int clk_sleeping_gated_fixed_prepare(struct clk_hw *hw)
|
||||
+{
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = clk_gated_fixed_prepare(hw);
|
||||
+ if (ret)
|
||||
+ return ret;
|
||||
+
|
||||
+ ret = clk_sleeping_gpio_gate_prepare(hw);
|
||||
+ if (ret)
|
||||
+ clk_gated_fixed_unprepare(hw);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void clk_sleeping_gated_fixed_unprepare(struct clk_hw *hw)
|
||||
+{
|
||||
+ clk_gated_fixed_unprepare(hw);
|
||||
+ clk_sleeping_gpio_gate_unprepare(hw);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Fixed gated clock with non-sleeping gpio.
|
||||
+ *
|
||||
+ * Enabling the supply regulator and switching the enable-gpio happens
|
||||
+ * both in the prepare step.
|
||||
+ * is_prepared only needs to check the gpio state, as toggling the
|
||||
+ * gpio is the last step when preparing.
|
||||
+ */
|
||||
+static const struct clk_ops clk_sleeping_gated_fixed_ops = {
|
||||
+ .prepare = clk_sleeping_gated_fixed_prepare,
|
||||
+ .unprepare = clk_sleeping_gated_fixed_unprepare,
|
||||
+ .is_prepared = clk_sleeping_gpio_gate_is_prepared,
|
||||
+ .recalc_rate = clk_gated_fixed_recalc_rate,
|
||||
+};
|
||||
+
|
||||
+static int clk_gated_fixed_probe(struct platform_device *pdev)
|
||||
+{
|
||||
+ struct device *dev = &pdev->dev;
|
||||
+ struct clk_gated_fixed *clk;
|
||||
+ const struct clk_ops *ops;
|
||||
+ const char *clk_name;
|
||||
+ u32 rate;
|
||||
+ int ret;
|
||||
+
|
||||
+ clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL);
|
||||
+ if (!clk)
|
||||
+ return -ENOMEM;
|
||||
+
|
||||
+ ret = device_property_read_u32(dev, "clock-frequency", &rate);
|
||||
+ if (ret)
|
||||
+ return dev_err_probe(dev, ret, "Failed to get clock-frequency\n");
|
||||
+ clk->rate = rate;
|
||||
+
|
||||
+ ret = device_property_read_string(dev, "clock-output-names", &clk_name);
|
||||
+ if (ret)
|
||||
+ clk_name = fwnode_get_name(dev->fwnode);
|
||||
+
|
||||
+ clk->supply = devm_regulator_get_optional(dev, "vdd");
|
||||
+ if (IS_ERR(clk->supply)) {
|
||||
+ if (PTR_ERR(clk->supply) != -ENODEV)
|
||||
+ return dev_err_probe(dev, PTR_ERR(clk->supply),
|
||||
+ "Failed to get regulator\n");
|
||||
+ clk->supply = NULL;
|
||||
+ }
|
||||
+
|
||||
+ clk->clk_gpio.gpiod = devm_gpiod_get_optional(dev, "enable",
|
||||
+ GPIOD_OUT_LOW);
|
||||
+ if (IS_ERR(clk->clk_gpio.gpiod))
|
||||
+ return dev_err_probe(dev, PTR_ERR(clk->clk_gpio.gpiod),
|
||||
+ "Failed to get gpio\n");
|
||||
+
|
||||
+ if (gpiod_cansleep(clk->clk_gpio.gpiod))
|
||||
+ ops = &clk_sleeping_gated_fixed_ops;
|
||||
+ else
|
||||
+ ops = &clk_gated_fixed_ops;
|
||||
+
|
||||
+ clk->clk_gpio.hw.init = CLK_HW_INIT_NO_PARENT(clk_name, ops, 0);
|
||||
+
|
||||
+ /* register the clock */
|
||||
+ ret = devm_clk_hw_register(dev, &clk->clk_gpio.hw);
|
||||
+ if (ret)
|
||||
+ return dev_err_probe(dev, ret,
|
||||
+ "Failed to register clock\n");
|
||||
+
|
||||
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
|
||||
+ &clk->clk_gpio.hw);
|
||||
+ if (ret)
|
||||
+ return dev_err_probe(dev, ret,
|
||||
+ "Failed to register clock provider\n");
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static const struct of_device_id gated_fixed_clk_match_table[] = {
|
||||
+ { .compatible = "gated-fixed-clock" },
|
||||
+ { /* sentinel */ }
|
||||
+};
|
||||
+
|
||||
+static struct platform_driver gated_fixed_clk_driver = {
|
||||
+ .probe = clk_gated_fixed_probe,
|
||||
+ .driver = {
|
||||
+ .name = "gated-fixed-clk",
|
||||
+ .of_match_table = gated_fixed_clk_match_table,
|
||||
+ },
|
||||
+};
|
||||
+builtin_platform_driver(gated_fixed_clk_driver);
|
Reference in New Issue
Block a user